I have 2 button controls. When I click one i'm trying to determine which one caused a postback in the page load. How to do determine this?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- Generic Generics in Managed C++
- How to store image outside of the website's ro
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
What about using CommandName and CommandArgument has shown in this example. This way you can have just one handler.
Really input with type button sends its value within post request. For example if you have you'll get in Post button-name=Quote like it's simple text input. So you can just check if post contains value for the button using code like following (sorry for my vb):
Dim isQuote As Boolean = HttpContext.Current.Request.Form(SubmitQuote.UniqueID) IsNot Nothing
so if it's not Nothing (null) then post has been sent by SubmitQuote button.
BTW for me HttpContext.Current.Request("__EVENTTARGET") didn't work either.
In my implementation there are several forms on my page; if a post-back was triggered by certain button controls further operations are necessary.
The controls are of the following type, which do not populate
Request["__EVENTTARGET"]
I determine if the following button controls instigated the post-back, by reviewing that the
UniqueID
of the control was passed to the form request within thePage_Load
sub:To simply handle whether the following nested image button instigated the post-back I take advantage of the
OnClientClick
attribute which calls to a javascript function that will populate the value of a supplementary hidden field control with theUniqueID
of the instigating control, then review the hidden control value similarly in thePage_Lode
sub:The
Page_Load
would then implement by some means:on page load check this
Do you come from a Classic ASP background? When I first used ASP.NET, the same question occurred to me.
Consider an alternative approach:
Rather than detect the postback in the Form_Load, and then figure out what triggered it, create a specific event handler for each of your buttons. This is the whole point of Web Forms - so you can develop apps in very similar ways as you would Windows applications.