input name and id changes when set runat=server

前端 未结 6 1744
终归单人心
终归单人心 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条回答
  •  一生所求
    2020-12-01 18:45

    This is because you're using MasterPages.

    Controls contained within a content page take on a dynamic ID based on the Master Page hierarchy in order to avoid duplication of IDs.

    If you need to reference the control IDs and names in client-side script, you can use <%= first_name.ClientID %>.

    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.

    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:

    
    

提交回复
热议问题