The Artima Developer Community
Sponsored Link

.NET Buzz Forum
ASP.NET Control ID and postback

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Peter van Ooijen

Posts: 284
Nickname: petergekko
Registered: Sep, 2003

Peter van Ooijen is a .NET devloper/architect for Gekko Software
ASP.NET Control ID and postback Posted: May 31, 2005 4:12 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Peter van Ooijen.
Original Post: ASP.NET Control ID and postback
Feed Title: Peter's Gekko
Feed URL: /error.htm?aspxerrorpath=/blogs/peter.van.ooijen/rss.aspx
Feed Description: My weblog cotains tips tricks and opinions on ASP.NET, tablet PC's and tech in general.
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Peter van Ooijen
Latest Posts From Peter's Gekko

Advertisement

Controls on your webforms all have an ID, like TextBox1, LinkButtonAdd, etc. This ID is not the internal Id used by ASP.NET. In case you have a datagrid with multiple rows, each having a Select link button you would have a problem. In case you have a web usercontrol on your page with a Button1 on it and a Button1 on the hosting page that would result in a conflict as well. The internal name is composed of the control id and the control containing the control.

Internal control names look like

LinkButton1 A link button on the page itself
WebUserControl11:LinkButton1 A link button on a usercontrol
WebUserControl11:DataGrid1:_ctl4:_ctl0   A linkbutton in a datgrid row on an usercontrol

At runtime you can read this Id from the control's ClientID property. It's value is in the request of a postback. In an earlier post I showed how to read it form the _EVENTTARGET form variable to find out which control had caused the postback. As Andrew noted this form variable is empty in case of a button causing the postback and wondered how he still could find out which button had caused the postback.

Well, if you inspect the AllKeys property of the Request.Form you will see that item 3 contains the id of the control posting back But this item3 is only in the collection when a button posts back, not when an asp.net specific control like a linkbutton or dropdownlist caused it. So a better version of my previous post would be

string postbackControlId;

if (Request.Form.AllKeys.GetUpperBound(0) > 2)
   postbackControlId = Request.Form.AllKeys[3];
else
   postbackControlId = Request.Form["__EVENTTARGET"];

// Fiddle the control id out of the string

 

Read: ASP.NET Control ID and postback

Topic: What I want out of Biztalk Previous Topic   Next Topic Topic: Blogger Experts

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use