User Control Static Name Option?

喜欢而已 提交于 2019-12-22 07:12:26

问题


I know there is a way to force asp web user controls (ascx) to use static ID's so they don't get appended with all the appended naming garbage...but is there way to do the same for the"name" attribute? Specifically, in this case, for DDL's? JQuery needs a specific name and I need to stop .NET from doing this.


回答1:


Not possible in ASP.Net for now ... I've found this combination to be an acceptable solution.

Add the ClientIDMode="Static" to the control:

<asp:HiddenField ID="HiddenField1" runat="server" ClientIDMode="Static" />

Using JQuery, on document ready, set the name attribute on the control to the value of its id:

$(document).ready(function () {

            // alert($("#HiddenField1").attr("name"));

            $("#HiddenField1").attr("name", "HiddenField1");

            // alert($("#HiddenField1").attr("name"));
        });



回答2:


Try adding ClientIDMode="Static" to the control tag.

<asp:FileUpload ID="FileUpload1" runat="server" ClientIDMode="Static" />


来源:https://stackoverflow.com/questions/10216882/user-control-static-name-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!