want to link form.submit to button_clik method

  • Thread starter Thread starter Billy
  • Start date Start date
B

Billy

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
 
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?
 
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 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 said:
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


.
 
Back
Top