__Click event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

All,

I have a ASPX page that handles a click event of a button and also have a
code behind for the button - I would like to handle the click event of the
webform first and then execute the code in the codebehind for the button is
this possible?

Thanks
Msuk
 
That's a fairly common scenario. Try this?

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add("onclick", _
"alert('Client side click');return true;")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Handled the server event at " & _
Now.ToLongTimeString
End Sub

<p>
<asp:button id="Button1" runat="server"
Text="Button"></asp:button></p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>

Ken
Microsoft MVP [ASP.NET]
 
I think Ken didn't answer the question which was about if we could fire the
event in the codebehind first then fire the client side event.
I have the same question. I was excited first. But I after read and test the
code. It didn't work the way we want.

Thanks
David
Ken Cox said:
That's a fairly common scenario. Try this?

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add("onclick", _
"alert('Client side click');return true;")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Handled the server event at " & _
Now.ToLongTimeString
End Sub

<p>
<asp:button id="Button1" runat="server"
Text="Button"></asp:button></p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>

Ken
Microsoft MVP [ASP.NET]

msuk said:
All,

I have a ASPX page that handles a click event of a button and also have a
code behind for the button - I would like to handle the click event of
the
webform first and then execute the code in the codebehind for the button
is
this possible?

Thanks
Msuk
 
Back
Top