Creating unique id for textbox
i like to have unique ids for textboxes and hidden filds .is there any property which will give unique id in asp.net ?
something like
<asp:text开发者_StackOverflowbox id="ctr001_1" runat="server" uniqueid="textbox" />
1st thing, why do you need to set the UniqueID property? FYI, ASP.NET web server controls has its own auto-generated readonly UniqueID property that you can access in your coding like below:
Textbox1.UniqueID()
The UniqueID is generated based on the control hierarchy, and each control's UniqueID property is, obviously, unique.
You need to use the TextBox form System.Web.UI.WebControls there you have property UniqueID.
http://msdn.microsoft.com/en-us/library/system.web.ui.control.uniqueid.aspx
Hm, not sure if this is what you are trying to achieve, but try this:
Set an attribute to your control, for example uniqueid="textbox" as you've done, then access the id by myControl.Attributes["uniqueid"].
ASP.NET will generate a UniqueID for the both TextBox and HiddenField on the page. Simply add each tag in markup and specify the ID:
<asp:textbox id="TextBox1" runat="server" />
<asp:HiddenField id="HiddenField1" runat="server" />
Both of these values can be accessed in the codebehind by:
TextBox1.Text
HiddenField1.Value
You can also see their Unquie ClientID by look at:
TextBox1.ClientID
HiddenValue1.ClientID
精彩评论