me crazy! Pulling one in from a control or within a master page, for
example, causes .NET to add class info to the "name" attribute. So, if
I have a control that contains:
<input class="TextField" id="foo" runat="server"/
It ultimately renders as <input name="_ctl0:[control ID]:foo"
type="text" id="_ctl0_[control ID]_foo" class="TextField" /
This, of course, makes it problematic to refer to these forms fields
via javascript. I've also got plain-vanilla HTML input fields I'm
rendering via XML that are named properly.
I realize I could convert EVERYTHING over to .NET controls and
validation, but you know what? I don't want to, and I shouldn't have
to. Is there any way to tell .NET to render the Name (it can keep ID)
attribute the way I want, short of creating a custom derived class for
each type of HtmlInput type to override the render method? And if I do
so, will I break things like ViewState?In javascript, you have to refer not to the hard coded id, but to a
dynamically emitted ClientID. If you look at the ASP.NET controls, they all
have a serverside ClientID property which is what the actual 'id' in the
HTML will be. So create a javascript variable, the value of which gets set
once in the beginning by Response.Writing the ClientID property or by <%=
%>, or whatever. Then, use that javascript variable all over the place to
refer to the control.
"Josh Wolf" <joshwolf@.gmail.com> wrote in message
news:1143736827.696279.135100@.z34g2000cwc.googlegr oups.com...
> The naming conventions that .NET uses in its HTML controls are driving
> me crazy! Pulling one in from a control or within a master page, for
> example, causes .NET to add class info to the "name" attribute. So, if
> I have a control that contains:
> <input class="TextField" id="foo" runat="server"/>
> It ultimately renders as <input name="_ctl0:[control ID]:foo"
> type="text" id="_ctl0_[control ID]_foo" class="TextField" />
> This, of course, makes it problematic to refer to these forms fields
> via javascript. I've also got plain-vanilla HTML input fields I'm
> rendering via XML that are named properly.
> I realize I could convert EVERYTHING over to .NET controls and
> validation, but you know what? I don't want to, and I shouldn't have
> to. Is there any way to tell .NET to render the Name (it can keep ID)
> attribute the way I want, short of creating a custom derived class for
> each type of HtmlInput type to override the render method? And if I do
> so, will I break things like ViewState?
Preventing ASP.NET from generating unique ID's
http://www.wilcob.com/Wilco/News/AspNetIDOverride.aspx
"Josh Wolf" <joshwolf@.gmail.com> wrote in message
news:1143736827.696279.135100@.z34g2000cwc.googlegr oups.com...
> The naming conventions that .NET uses in its HTML controls are driving
> me crazy! Pulling one in from a control or within a master page, for
> example, causes .NET to add class info to the "name" attribute. So, if
> I have a control that contains:
> <input class="TextField" id="foo" runat="server"/>
> It ultimately renders as <input name="_ctl0:[control ID]:foo"
> type="text" id="_ctl0_[control ID]_foo" class="TextField" />
> This, of course, makes it problematic to refer to these forms fields
> via javascript. I've also got plain-vanilla HTML input fields I'm
> rendering via XML that are named properly.
> I realize I could convert EVERYTHING over to .NET controls and
> validation, but you know what? I don't want to, and I shouldn't have
> to. Is there any way to tell .NET to render the Name (it can keep ID)
> attribute the way I want, short of creating a custom derived class for
> each type of HtmlInput type to override the render method? And if I do
> so, will I break things like ViewState?
0 comments:
Post a Comment