输入姓名和身份证更改时设置RUNAT =服务器 [英] input name and id changes when set runat=server
问题描述
在我的表单我需要插入类型文本不同的输入。输入信号必须有名称和ID的HTML控件。因为我把这种形式到外部URL。
In my form I need to insert different inputs of type "text". The inputs must be html controls with name and id's. Because I send this form to a external url.
有关验证我的Runat在所有输入=服务器上,然后我可以使用的RequiredFieldValidator。
For the validation I do runat=server in all inputs and then I can use requiredfieldvalidator.
但问题是,当我看到在源代码中访问的名称和ID的都改了页之后。 例如:
But the problem is when I look in the source after visiting the page the name and id's are all changed. for example
<input id="first_name" class="formright" type="text" name="first_name" runat="server" />
修改
<input name="ctl00$cphContent$first_name" type="text" id="ctl00_cphContent_first_name" class="formright">
我一定要使用HTML控件,因为外部一项PostBackUrl看名称和ID值,找到控制。所以我不能用asp控制。这是因为我使用的HTML控件与RUNAT =服务器
I have to use html controls because the external postbackurl looks at the name and id values to find the control. So I can't use asp controls. It is because of that I used html controls with runat=server
我AP preciate任何帮助
I appreciate any help
推荐答案
这是因为你使用MasterPages。
This is because you're using MasterPages.
包含在内容页控件采取基于母版页层次结构,以避免ID的重复一个动态的ID。
Controls contained within a content page take on a dynamic ID based on the Master Page hierarchy in order to avoid duplication of IDs.
如果您需要引用控制ID和名称在客户端脚本,您可以使用&LT;%= first_name.ClientID%GT;
If you need to reference the control IDs and names in client-side script, you can use <%= first_name.ClientID %>
.
如果您使用的是.NET4可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx"><$c$c>ClientIDMode="Static"$c$c>使生成的ID一致,虽然这有它自己的ID冲突的警告时,例如,使用一个页面上的同一用户控制的多个实例。里克施特拉尔概述了这些这里。
If you're using .NET4 you can use ClientIDMode="Static"
to make the generated IDs consistent, although this comes with its own ID-conflict caveats when, for example, using multiple instances of the same user control on a page. Rick Strahl outlines those here.
不过,如果你使用ASP.NET验证那么一切都应该罚款。而不是使用的HTML 输入
你应该使用的 ASP.NET TextBox控件:
However, if you're using ASP.NET validators then everything should be fine. Instead of using an HTML input
you should use an ASP.NET TextBox control:
<asp:TextBox id="first_name" runat="server" CssClass="formright" />
这篇关于输入姓名和身份证更改时设置RUNAT =服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!