473,387 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Me vs. .NET HTML Control naming conventions

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?

Mar 30 '06 #1
2 3775
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" <jo******@gmail.com> wrote in message
news:11**********************@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:

&lt;input class="TextField" id="foo" runat="server"/&gt;

It ultimately renders as &lt;input name="_ctl0:[control ID]:foo"
type="text" id="_ctl0_[control ID]_foo" class="TextField" /&gt;

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?

Mar 30 '06 #2
Preventing ASP.NET from generating unique ID's
http://www.wilcob.com/Wilco/News/AspNetIDOverride.aspx
"Josh Wolf" <jo******@gmail.com> wrote in message
news:11**********************@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:

&lt;input class="TextField" id="foo" runat="server"/&gt;

It ultimately renders as &lt;input name="_ctl0:[control ID]:foo"
type="text" id="_ctl0_[control ID]_foo" class="TextField" /&gt;

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?

Mar 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: cmiddlebrook | last post by:
Hi there, I keep finding myself getting inconsistent with naming conventions for things like member variables, class names etc and I just want to find something that suits me and stick to it. I...
1
by: clintonG | last post by:
Does the use of DTD, XML Schema and similar constructs adopt the use of C# naming conventions? If so how do I make the distinction of how to apply C# conventions with XML elements, attributes and...
4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
5
by: rastaman | last post by:
Hi all, I know of the existence of Object Naming Conventions for Visual Basic 6. Now I'm reading some books about VB .NET, but the names used for the objects are button1, picturebox1, etc. I...
9
by: kevininstructor | last post by:
Greetings, I am in the process of creating naming conventions for VB.NET controls i.e. CheckBox -> chkShowThisOnStartup ListBoxt -> lstSomeList What I am looking for other developers...
6
by: rlrcstr | last post by:
The DBA team at the office controls the naming conventions for the database structure, but their naming convention are rather tedious. So typically I create a global module that I use as a mapping...
4
by: Sturdy | last post by:
Hi, I'm new to C# and .NET. I'm a first time user of Visual C# 2005 Express and have a very basic question. I've looked at several links and lots of docs but can't find any tips on naming multiple...
35
by: Smithers | last post by:
Is it common practise to begin the name of form classes with "frm" (e.g., frmOneForm, frmAnotherForm). Or is that generally considered an outdated convention? If not "frm" what is a common or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.