B
Bob
Hello,
For web controls which can invoke __doPostBack. At the page load, I
supposedly can know who caused the PostBack by checking
Request.Form("__EVENTTARGET"). It does work for the dropdownlist, however
it doesn't work for the button. When the button is clicked, on page load,
Request.Form("__EVENTTARGET") ="". If I call
Page.RegisterHiddenField("__EVENTTARGET", "FakeButton"), then when the
button is clicked, Request.Form("__EVENTTARGET") ="FakeButton". It looks
like when the button on the page is clicked, ASP.NET does NOT ignore the
hidden field in favor of the actual button click.
Is there something I missed? Thanks for your input.
Here is the code snippets.
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
Page.RegisterHiddenField("__EVENTTARGET", "FakeButton")
If Request.Form("__EVENTTARGET") = "Button1" Then
'do one sth
ElseIf Request.Form("__EVENTTARGET") = "Button2" Then
'do another sth
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim b As Button = CType(sender, Button)
Label1.Text = "You clicked " & b.ID
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Label1.Text = "You clicked " & sender.ID
End Sub
For web controls which can invoke __doPostBack. At the page load, I
supposedly can know who caused the PostBack by checking
Request.Form("__EVENTTARGET"). It does work for the dropdownlist, however
it doesn't work for the button. When the button is clicked, on page load,
Request.Form("__EVENTTARGET") ="". If I call
Page.RegisterHiddenField("__EVENTTARGET", "FakeButton"), then when the
button is clicked, Request.Form("__EVENTTARGET") ="FakeButton". It looks
like when the button on the page is clicked, ASP.NET does NOT ignore the
hidden field in favor of the actual button click.
Is there something I missed? Thanks for your input.
Here is the code snippets.
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
Page.RegisterHiddenField("__EVENTTARGET", "FakeButton")
If Request.Form("__EVENTTARGET") = "Button1" Then
'do one sth
ElseIf Request.Form("__EVENTTARGET") = "Button2" Then
'do another sth
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim b As Button = CType(sender, Button)
Label1.Text = "You clicked " & b.ID
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Label1.Text = "You clicked " & sender.ID
End Sub