首页 > c# > 将文本框声明为具有唯一名称

将文本框声明为具有唯一名称 (Exending Textbox to have a Unique Name)

2010-08-23 c#asp.net

问题

是否可以使文本框具有唯一名称?我尝试过使用UniqueID poperty,但是Request.Form(“UniqueID”)无法访问

解决方法

默认情况下,所有ASP.NET控件都会收到唯一的ID和名称(复选框和单选按钮除外,它们可能具有相同的名称,但ID不同)。

如果你给TextBox一个ID,就像这样:

<asp:TextBox ID="txtFirstName" runat="server" />

然后你应该能够在代码后面作为该名称的成员(txtFirstName)访问它。

如果您想通过Request.Form访问,您可以像这样访问它:

string textBoxValue = Request.Form[txtFirstName.ClientID]

问题

Is it possible to Exend Textbox to have a Unique Name ? I have tried using UniqueID poperty,but this is not accessible with Request.Form("UniqueID")

解决方法

By default, all ASP.NET controls receive a unique ID and name (except for checkboxes and radio buttons which may have the same name, but different IDs).

If you gave your TextBox an ID, like so:

<asp:TextBox ID="txtFirstName" runat="server" />

Then you should be able to access it in code behind as a member of that name (txtFirstName).

If you want access through Request.Form, you can access it like so:

string textBoxValue = Request.Form[txtFirstName.ClientID]
相似信息