__Click event

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
 
K

Ken Cox [Microsoft MVP]

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]
 
D

David

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top