input name and id changes when set runat=server

前端 未结 6 1736
终归单人心
终归单人心 2020-12-01 17:51

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.

For

6条回答
  •  -上瘾入骨i
    2020-12-01 18:30

    ClientIDMode="Static"
    

    This usefully locks the ID of any runat="server" control, however it does not lock the 'name' attribute of a html input element.

    Seeing in this instance the only reason to have the runat="server" attribute on the input is to use .Net validation, I would suggest using an external JS library such as jQuery to handle this.

    If however, like me, you need to alter the value attribute, the only work around I can see is a rather messy one. If you remove the runat="server" from the input, you can place a server control, such as a literal, within the value="" attribute.

    For example:

    "  />
    

    Please don't have a go at me for such bad coding practises, it's intended as a last resort workaround to keep the name attribute from changing to a .Net style name.

    Does anyone else know of another way to fix the name? (The form element is not defined as runat="server", but it's embedded within the normal .Net form, which is why the server is attaching it to the main form tree)

提交回复
热议问题