Hello Richard,
I think either way is ok. Actually ASP.NET internally checks the event
target via the Request.Form as well. I just want to mention when can use
__EVENTTARGET to get the clicked button id. To test, please create a new
web application and try following code:
Test1:
Aspx:
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click1" />
Aspx.cs:
protected void Page_PreInit(object sender, EventArgs e)
{
if (IsPostBack)
{
if (Request.Form["__EVENTTARGET"] != null &&
Request.Form["__EVENTTARGET"]!=String.Empty)
{
this.Label1.Text = Request.Form["__EVENTTARGET"];
}
else {
this.Label1.Text = "No value";
}
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
}
You can see the Label will show "No value" when you click the button.
Test2:
If we try this:
<asp:Button ID="Button1" runat="server" Text="Button"
UseSubmitBehavior="false"
onclick="Button1_Click1" />
The Label will show the button id.
The difference is due to adding the UseSubmitBehavior="false", which
changes the HTML rendered by the ASP.NET button control. We can view source
to see what's the rendered HTML.
The HTML rendered by Test1:
<span id="Label1"></span>
<input type="submit" name="Button1" value="Button" id="Button1" />
The HTML rendered by Test2:
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<span id="Label1">Button1</span>
<input type="button" name="Button1" value="Button"
onclick="javascript
:__doPostBack('Button1','')" id="Button1" />
We can see in Test2 the ASP.NET button control will call javascript
function when we click the button. In that function it assigns the id to
the __EVENTTARGET hidden field thus we can get the id at server side via
Request.Form. (As we know the hidden input will be submitted to the server
along with the form).
Then the question is how the ASP.NET can know which button is clicked if
the id cannot be retrieved from the __EVENTTARGET, namely in the Test1 how
the button click event can fire? We need to notice another difference in
the html, that is the type of the <inputrendered by the ASP.NET button
control. In the Test1 it's of type submit while in Test2 it's of type
button. The browser will treat the submit input differently. The id of the
submit input will be sent to the request along with the form just as the
hidden input. On the ProcessPostData stage of the page life cycle the
ASP.NET page will check all the posted data and use FindControl method to
find the control. When a reference is got it will check if the control
implements IPostBackEventHandler. If it does the page will call
this.RegisterRequiresRaiseEvent(control.PostBackEv entHandler) to register
the event handler for later call. Since the button implements this
interface it can benefit from this feature as long as its id is posted to
server on postback.
If you need further questions please feel free to ask.
Regards,
Allen Chen
Microsoft Online Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "RichB" <ri**********@community.nospam>
| References: <O1**************@TK2MSFTNGP06.phx.gbl>
<On**************@TK2MSFTNGHUB02.phx.gbl>
| Subject: Re: Dynamically Add and Remove Accordion Control Panes
| Date: Tue, 4 Nov 2008 11:39:11 -0000
| Lines: 109
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| X-RFC2646: Format=Flowed; Original
| Message-ID: <ef**************@TK2MSFTNGP02.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 93-96-97-68.zone4.bethere.co.uk 93.96.97.68
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP02.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl
microsoft.public.dotnet.framework.aspnet:79170
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Allen,
|
| I have now managed to resolve this. I noticed in another post a similar
| problem which uses the
| HttpContext.Current.Request.Form["__EVENTTARGET"] string to get the
button
| clicked and process it within the Page_PreInit rather than in the event.
| This works fine, unless you believe that this approach is inappropriate,
| then please ignore my email with example code.
|
| This seems to be an easy approach, far easier than using the click event.
| How should I decide whether to use the click event versus this method?
|
| Thanks,
| Richard
|
|
|
|
| "Allen Chen [MSFT]" <v-******@online.microsoft.comwrote in message
| news:On**************@TK2MSFTNGHUB02.phx.gbl...
| Hi Richard,
| >
| Quote from Richard=========================================== =======
| >
| However I also want to be able to remove the
| panes. I have tried to include this, but find that when I first add the
| pane
| the remove event does not get handled, though thereafter it is handled
| without problems.
| ==================================================
| >
| Sorry Richard but I'm not quite clear about what you mentioned above. Do
| you mean when you add the pane the remove event will not fire? If so I
| think it's normal. Why the remove event need to fire when we add the
pane?
| From the code you provided I think the Remove_Pane will be called if
user
| clicks the removeLB LinkButton.
| >
| I could not find the definition of LocationInfoDTO and the other
controls
| defined in the aspx so I cannot reproduce it on my side. Could you send
me
| a demo project and clarify the problem? My email is
|
v-******@microsoft.com.
| >
| Regards,
| Allen Chen
| Microsoft Online Support
| >
| Delighting our customers is our #1 priority. We welcome your comments
and
| suggestions about how we can improve the support we provide to you.
Please
| feel free to let my manager know what you think of the level of service
| provided. You can send feedback directly to my manager at:
|
ms****@microsoft.com.
| >
| ==================================================
| Get notification to my posts through email? Please refer to
| >
http://msdn.microsoft.com/en-us/subs...#notifications.
| >
| Note: MSDN Managed Newsgroup support offering is for non-urgent issues
| where an initial response from the community or a Microsoft Support
| Engineer within 2 business day is acceptable. Please note that each
follow
| up response may take approximately 2 business days as the support
| professional working with you may need further investigation to reach
the
| most efficient resolution. The offering is not appropriate for
situations
| that require urgent, real-time or phone-based interactions. Issues of
this
| nature are best handled working with a dedicated Microsoft Support
| Engineer
| by contacting Microsoft Customer Support Services (CSS) at
|
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
| ==================================================
| This posting is provided "AS IS" with no warranties, and confers no
| rights.
| >
| --------------------
| | From: "RichB" <ri**********@community.nospam>
| | Subject: Dynamically Add and Remove Accordion Control Panes
| | Date: Fri, 31 Oct 2008 15:54:01 -0000
| | Lines: 178
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
| | X-RFC2646: Format=Flowed; Original
| | Message-ID: <O1**************@TK2MSFTNGP06.phx.gbl>
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: 93-96-97-68.zone4.bethere.co.uk 93.96.97.68
| | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP06.phx.gbl
| | Xref: TK2MSFTNGHUB02.phx.gbl
| microsoft.public.dotnet.framework.aspnet:78994
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| |
| | I have a Page which contains an Accordion Control with dynamically
added
| | custom panes. I have added a link button to the page to allow further
| panes
| | to be added and this works. However I also want to be able to remove
the
| | panes. I have tried to include this, but find that when I first add
the
| pane
| | the remove event does not get handled, though thereafter it is handled
| | without problems. I would be grateful if someone could take a look and
| | advise why I am getting this problem (I have attached all relevant
| code).
| |
| | Thanks, Richard
| |
| |
| |
| |
| >
|
|
|