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 6 1639
Why not just check the "sender" event argument of the Page_Load event? This
is what it is there for. Just check sender.getType.toString and then you'll
know what kind of control caused the postback. Then you could cast sender
into that type and check its name.
"Bob" <bo******@yahoo.com> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl... 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
Hi Scott,
While I did not check all the other methods, because I think it becomes a
lot of rubish in the load event, while there is a good methode, that only
needs three lines.
In VB.net as example that is
\\\
sub from page control event
todo
end sub
///
Did I test your sample because I could not believe it, but you never knows.
(getting the type of sender is in webforms not that simple as in
windowforms)
I did try it with only one serverside button on the page
\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As String = sender.GetType.ToString
'returns always "asp.webform1.aspx"
End Sub
///
When I did understand something wrong let me know?
Cor Why not just check the "sender" event argument of the Page_Load event?
This is what it is there for. Just check sender.getType.toString and then
you'll know what kind of control caused the postback. Then you could cast sender into that type and check its name.
No, you are right Cor. I have used sender in Windows Forms projects without
a problem and just assumed that it would work the same way in on a Web Form.
Thanks.
"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Scott,
While I did not check all the other methods, because I think it becomes a lot of rubish in the load event, while there is a good methode, that only needs three lines. In VB.net as example that is \\\ sub from page control event todo end sub ///
Did I test your sample because I could not believe it, but you never
knows. (getting the type of sender is in webforms not that simple as in windowforms)
I did try it with only one serverside button on the page \\\ Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim a As String = sender.GetType.ToString 'returns always "asp.webform1.aspx" End Sub ///
When I did understand something wrong let me know?
Cor
Why not just check the "sender" event argument of the Page_Load event? This is what it is there for. Just check sender.getType.toString and then you'll know what kind of control caused the postback. Then you could cast
sender into that type and check its name.
That is also what I got in webform. SO back to the question. How can I know
which button invoked the button event?
"Scott M." <s-***@badspamsnet.net> wrote in message
news:#u**************@TK2MSFTNGP09.phx.gbl... No, you are right Cor. I have used sender in Windows Forms projects
without a problem and just assumed that it would work the same way in on a Web
Form. Thanks.
"Cor" <no*@non.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Scott,
While I did not check all the other methods, because I think it becomes
a lot of rubish in the load event, while there is a good methode, that
only needs three lines. In VB.net as example that is \\\ sub from page control event todo end sub ///
Did I test your sample because I could not believe it, but you never knows. (getting the type of sender is in webforms not that simple as in windowforms)
I did try it with only one serverside button on the page \\\ Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim a As String = sender.GetType.ToString 'returns always "asp.webform1.aspx" End Sub ///
When I did understand something wrong let me know?
Cor
Why not just check the "sender" event argument of the Page_Load event? This is what it is there for. Just check sender.getType.toString and then you'll know what kind of control caused the postback. Then you could cast sender into that type and check its name.
You could add a custom value to VIEWSTATE that differs depending on what
control was interacted with:
ViewState.Add("EventStartedBy", controlName)
You could then check the "EventStartedBy" key in ViewState on the PostBack
via a Select statement to see what its value is.
I'm sure there's got to be another way, but this should work.
"Bob" <bo******@yahoo.com> wrote in message
news:OT**************@TK2MSFTNGP10.phx.gbl... That is also what I got in webform. SO back to the question. How can I
know which button invoked the button event?
"Scott M." <s-***@badspamsnet.net> wrote in message news:#u**************@TK2MSFTNGP09.phx.gbl... No, you are right Cor. I have used sender in Windows Forms projects without a problem and just assumed that it would work the same way in on a Web Form. Thanks.
"Cor" <no*@non.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Hi Scott,
While I did not check all the other methods, because I think it
becomes a lot of rubish in the load event, while there is a good methode, that only needs three lines. In VB.net as example that is \\\ sub from page control event todo end sub ///
Did I test your sample because I could not believe it, but you never knows. (getting the type of sender is in webforms not that simple as in windowforms)
I did try it with only one serverside button on the page \\\ Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Dim a As String = sender.GetType.ToString 'returns always "asp.webform1.aspx" End Sub ///
When I did understand something wrong let me know?
Cor
> Why not just check the "sender" event argument of the Page_Load
event? This > is what it is there for. Just check sender.getType.toString and
then you'll > know what kind of control caused the postback. Then you could cast
sender > into that type and check its name. >
Hi Bob,
Do you want to know what button did do the post back without to test them
all, or do you want absolute to test them in the load event.
For the first you can use dynamically made buttons and test it only once
(and I have made an example if you want) for the second I have no solution
and I think that will absolute become a big hash in the load event (I was
also thinking like Scott on the viewstate for that).
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Pavils Jurjans |
last post by:
Hallo,
I have been programming for restricted environments where Internet Explorer
is a standard, so I haven't stumbled upon this problem until now, when I
need to write a DOM-compatible code.
...
|
by: Earl Teigrob |
last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
|
by: Amit D.Shinde |
last post by:
I am adding a new picturebox control at runtime on the form
How can i create click event handler for this control
Amit Shinde
|
by: Beth |
last post by:
in the following:
this.ExitButton.Click += new System.EventHandler(this.ExitButton_Click);
if I saw an equation, such as y +=x;
then y = y+x.
But what is the meaning in the event handler. I...
|
by: james |
last post by:
Hello,
I am having a little trouble creating an event handler for a context menu
toolstripmenuitem.
I've seen various tutorials and so on, but I keep getting a bit stuck!
So far I have a second...
|
by: Joseph Geretz |
last post by:
I'm porting a C# Outlook Addin originally engineered as a COM Addin over to
use VSTO. I've gotten this to the point where my VSTO Addin installs its
Menu items and Toolbar buttons when Outlook...
|
by: John Kotuby |
last post by:
Hi guys,
I am converting a rather complicated database driven Web application from
classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The
original ASP application works quite...
|
by: =?Utf-8?B?UlJK?= |
last post by:
Hello,
I would like to add the Paint handler to the form. How to do it?
Thanks in advance.
|
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= |
last post by:
Hi all,
Recently I found an interesting question on C# forums about clearing event
handlers of an event. I tried to give it a solution, but failed. I am
interested to know how you guys take...
|
by: wolverine |
last post by:
Hi All,
In Mozilla Firefox, to onblur and onfocus event of each and every
html element, the browser itself will attach a native event handler. I
mean if you type,...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |