Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User Control Static Name Option?

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.

like image 307
John Kinane Avatar asked Apr 18 '12 19:04

John Kinane


1 Answers

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"));
        });
like image 159
Jorge Garcia Avatar answered Oct 29 '22 16:10

Jorge Garcia