【问题标题】:input "id" and "name" changes when set runat=server from设置 runat=server 时输入“id”和“name”发生变化
【发布时间】:2015-06-04 06:26:19
【问题描述】:

在我的表单中,我需要插入“隐藏”类型的不同输入。 输入必须是带有“名称”和“ID”的 html 控件。因为我将此表单发送到外部 url。

对于验证,我在隐藏输入中执行 runat=server,然后我可以使用 requiredfieldvalidator。

但问题是当我在访问页面后查看源代码时,名称已更改。例如

<input type="hidden" name="hotelIdform" value="" runat="server" id="hotelIdform">

改为

 <input name="ctl00$ctl00$Master_Body$child_center_content$hotelIdform" type="hidden" id="hotelIdform" value="b4ba78fc-0b62-4809-9dca-000972573139" />

我使用了 ClientIDMode="Static" ,只是 ID 没问题

请帮帮我

【问题讨论】:

    标签: c# html asp.net


    【解决方案1】:

    您似乎在使用母版页,而不是使用静态客户端 ID。因此,ASP.NET 在编译页面时会更改 ID。

    您需要将ClientIDMode 设置为Static

    请参考this SO post

    【讨论】:

    • 设置 ClientIDMode="Static" 时,ID 值正常但名称不变
    猜你喜欢
    • 2011-08-13
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 2016-04-29
    相关资源
    最近更新 更多