Connecting Tech Pros Worldwide Forums | Help | Site Map

want to link form.submit to button_clik method

Billy
Guest
 
Posts: n/a
#1: Nov 17 '05
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

Chris Jackson
Guest
 
Posts: n/a
#2: Nov 17 '05

re: want to link form.submit to button_clik method


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" <billy_lenrage@hotmail.com> wrote in message
news:010401c394cc$6d2c87e0$a301280a@phx.gbl...[color=blue]
> 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[/color]


Billy
Guest
 
Posts: n/a
#3: Nov 17 '05

re: want to link form.submit to button_clik method



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

[color=blue]
>-----Original Message-----
>The System.Web.UI.WebControls.Button object can render [/color]
HTML that already[color=blue]
>uses the onMouseDown event. Why not just use an input [/color]
type=button object[color=blue]
>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" <billy_lenrage@hotmail.com> wrote in message
>news:010401c394cc$6d2c87e0$a301280a@phx.gbl...[color=green]
>> 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 [/color][/color]
script,[color=blue][color=green]
>> 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[/color][/color]
()")[color=blue][color=green]
>>
>> End Function
>>
>> Private Sub BSubmit_Click(ByVal sender As [/color][/color]
System.Object,[color=blue][color=green]
>> ByVal e As System.EventArgs) Handles BSubmit.Click
>>
>> ' Some action is in the submit button Click event
>> [...]
>>
>> End Sub
>> </CODE>
>>
>> Thanks a lot!
>>
>> Billy[/color]
>
>
>.
>[/color]
Closed Thread


Similar ASP.NET bytes