asp.net form post

  • Thread starter Thread starter LIN
  • Start date Start date
L

LIN

hii im working on asp.net and i have a form which has 4 asp.net buttons ech
time i click on a button the page is posted now i want to know on pageload
which button has caused the post action.. of the page ...this is would help
me to write button specific events on tht page ....can any one help out in
this .....
 
LIN said:
hii im working on asp.net and i have a form which has 4 asp.net buttons ech
time i click on a button the page is posted now i want to know on pageload
which button has caused the post action.. of the page ...this is would help
me to write button specific events on tht page ....can any one help out in
this .....

Why not simply handle the Click events for all four buttons?
 
im actually writing a few lines of code on the click event of the button
...thts not the problem i want to capture the name of the button wheen the
form is posted i.e after the button is being clicked..i want to know which
button has made the form to post..
 
LIN said:
im actually writing a few lines of code on the click event of the button
..that is not the problem I want to capture the name of the button when the
form is posted i.e after the button is being clicked..I want to know which
button has made the form to post..

Lin,
Given a Button WebControl
<asp:Button id="Button1" Runat="server" Text="Button1"></asp:Button>

You can get the Button ID and Text as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myButton As Button = CType(sender, Button)
Dim myButtonID As String = myButton.ID
Dim myButtonName As String = myButton.Text
End Sub

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com
 
From within your Page_Load event you can look for the names of the buttons
in the Request.Form collection.
If the button name is present then you know that button caused the postback.
 
ok now i can find the button in the request.form on page load section ...for
wht do i check it for ....
pls note tht the button im using here is image button..pls lemme know

thanx
 
hii this is working for only a single button when i have more than a single
button and write the same code below ..both the button's are getting
executed ....i.e i get the messages from both the buttons ...wht do i do
now ..and one more thing the button im using here is an image button and not
a normal button

thanx


Carl Prothman said:
Lin,
Given a Button WebControl
<asp:Button id="Button1" Runat="server" Text="Button1"></asp:Button>

You can get the Button ID and Text as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
 
LIN said:
hii this is working for only a single button when i have more than a single
button and write the same code below ..both the button's are getting
executed ....i.e i get the messages from both the buttons ...wht do i do
now ..
and one more thing the button im using here is an image button and not
a normal button

Given two ImageButton WebControls

<asp:ImageButton id="ImageButton1" runat="server" ImageUrl="image1.jpg" />
<asp:ImageButton id="ImageButton2" runat="server" ImageUrl="image2.jpg" />

The events handlers (and code to get each ID) looks like:

Private Sub ImageButton1_Click(ByVal sender As System.Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click

Dim myImageButton As ImageButton = CType(sender, ImageButton)
Dim myImageButtonID As String = myImageButton.ID
End Sub

Private Sub ImageButton2_Click(ByVal sender As System.Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton2.Click

Dim myImageButton As ImageButton = CType(sender, ImageButton)
Dim myImageButtonID As String = myImageButton.ID
End Sub

When you click on a single ImageButton, the corresponding click event handler fires,
not both. If you are seeing both click event handlers fire for a single click on one of
the ImageButton, then post some sample code which repros the problem.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com
 
Back
Top