473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

want to link form.submit to button_clik method

Hi.

I'm new to asp.net and I'm trying to create a confirm
dialog box using the confirm() javascript function that
will pup once the submit button is pressed. My problem
is when I call document.forms[0].submit() in the script,
I would like to execute the code in the click event of
the submit button. How could I link this event to the
Form.submit function?

Here's the code :

<CODE>
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here
If Not Page.IsPostBack Then
Confirm("Do you want to continue?")
End If

End Sub

Function Confirm(ByVal Msg As String)

Dim sb As New System.Text.StringBuilder
sb.Append(" <SCRIPT LANGUAGE = javascript>")
sb.Append("<!-- " & vbCrLf)
sb.Append(" function confirmSave(){" & vbCrLf)
sb.Append(" if (confirm(" & """" & Msg & """" & "))
{" & vbCrLf)
sb.Append(" document.forms[0].submit();" & vbCrLf)
sb.Append(" }" & vbCrLf)
sb.Append("}" & vbCrLf)
sb.Append("--></script>" & vbCrLf)
RegisterClientScriptBlock("cs", sb.ToString)

BSubmit.Attributes.Add("onMousedown", "confirmSave()")

End Function

Private Sub BSubmit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BSubmit.Click

' Some action is in the submit button Click event
[...]

End Sub
</CODE>

Thanks a lot!

Billy
Nov 17 '05 #1
2 1932
The System.Web.UI.WebControls.Button object can render HTML that already
uses the onMouseDown event. Why not just use an input type=button object
which references that script directly?

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Billy" <bi***********@hotmail.com> wrote in message
news:01****************************@phx.gbl...
Hi.

I'm new to asp.net and I'm trying to create a confirm
dialog box using the confirm() javascript function that
will pup once the submit button is pressed. My problem
is when I call document.forms[0].submit() in the script,
I would like to execute the code in the click event of
the submit button. How could I link this event to the
Form.submit function?

Here's the code :

<CODE>
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here
If Not Page.IsPostBack Then
Confirm("Do you want to continue?")
End If

End Sub

Function Confirm(ByVal Msg As String)

Dim sb As New System.Text.StringBuilder
sb.Append(" <SCRIPT LANGUAGE = javascript>")
sb.Append("<!-- " & vbCrLf)
sb.Append(" function confirmSave(){" & vbCrLf)
sb.Append(" if (confirm(" & """" & Msg & """" & "))
{" & vbCrLf)
sb.Append(" document.forms[0].submit();" & vbCrLf)
sb.Append(" }" & vbCrLf)
sb.Append("}" & vbCrLf)
sb.Append("--></script>" & vbCrLf)
RegisterClientScriptBlock("cs", sb.ToString)

BSubmit.Attributes.Add("onMousedown", "confirmSave()")

End Function

Private Sub BSubmit_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles BSubmit.Click

' Some action is in the submit button Click event
[...]

End Sub
</CODE>

Thanks a lot!

Billy

Nov 17 '05 #2

I'm not sure what you mean. Do you want me to simply
replace the <asp:button> with a <input type="button">?
Do I add runat="server" to the input to put some code on
the click event? Is the input should reference to the
script via the onclick parameter...

So it should look like :

<input id="ConfirmButton" type="button"
value="Soumettre2" runat="server" onclick="ShowConfirm
();">

and the script

<script type =text/javascript >
function ShowConfirm()
{
if(confirm("Voulez-vous créer ce groupe?"))
{
document.Form1.submit();
}
}
</script>

Cause it isn't working more...

Thx

-----Original Message-----
The System.Web.UI.WebControls.Button object can render HTML that alreadyuses the onMouseDown event. Why not just use an input type=button objectwhich references that script directly?

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Billy" <bi***********@hotmail.com> wrote in message
news:01****************************@phx.gbl...
Hi.

I'm new to asp.net and I'm trying to create a confirm
dialog box using the confirm() javascript function that
will pup once the submit button is pressed. My problem
is when I call document.forms[0].submit() in the script, I would like to execute the code in the click event of
the submit button. How could I link this event to the
Form.submit function?

Here's the code :

<CODE>
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here
If Not Page.IsPostBack Then
Confirm("Do you want to continue?")
End If

End Sub

Function Confirm(ByVal Msg As String)

Dim sb As New System.Text.StringBuilder
sb.Append(" <SCRIPT LANGUAGE = javascript>")
sb.Append("<!-- " & vbCrLf)
sb.Append(" function confirmSave(){" & vbCrLf)
sb.Append(" if (confirm(" & """" & Msg & """" & "))
{" & vbCrLf)
sb.Append(" document.forms[0].submit();" & vbCrLf)
sb.Append(" }" & vbCrLf)
sb.Append("}" & vbCrLf)
sb.Append("--></script>" & vbCrLf)
RegisterClientScriptBlock("cs", sb.ToString)

BSubmit.Attributes.Add("onMousedown", "confirmSave ()")
End Function

Private Sub BSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BSubmit.Click

' Some action is in the submit button Click event
[...]

End Sub
</CODE>

Thanks a lot!

Billy

.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dodo | last post by:
Is it possible to create a link that can post a value to an ASP page without java?
1
by: Stanimir Stamenkov | last post by:
Here's an example: <form action="bogus" method="post"> <p> <a href="prev.cgi"><input type="submit" name="prev" value="< Back"></a> <a href="next.cgi"><input type="submit" name="next"...
10
by: | last post by:
Can I link to another page with a <input type=button> without javascript??? Thanks
2
by: Matt | last post by:
Can we click a link and it will submit the form to the other page? Usually we will submit the form to other page by clicking a submit button. Now I need to do the following, but what if I have...
2
by: Cardinal | last post by:
In the application I'm developing, I need a link to behave as a form submit. I set up a little test example below and it worked fine: <table> <tr> <form action="action1.cfm" method="POST"...
4
by: dschruth | last post by:
Hello. Can anybody solve this problem? I am using a server-side language (PERL) to *try* to POST data to a HTTPS login script that doesn't have a standard "submit" button. The form appears...
26
by: Mica Cooper | last post by:
Hi, I need to pass some info in a javascript submit. <a href="javascript:document.formName.submit();">Submit Form</a> Normally a link would do page.jsp?x1=1&x2=2&x3=3 and you would pull x1,...
3
by: Samuel Shulman | last post by:
Hi I need to add a link from one page to another and send a parameter NOT using the Get What would be normally the way to do that? Can I use the post method and how? Thank you, Samuel
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.