473,725 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Html Control Changing Name Value

I am working on a complex server control that dynamically creates an
HtmlInputHidden control that stores its value. As far as the postback
process is concerned, this hidden input acts as the control itself. So
when I render, I generate a proxy HtmlInputHidden like so:

protected virtual void Render(HtmlText Writer writer)
{
HtmlInputHidden hiddenInput = new HtmlInputHidden ();
hiddenInput.ID = ClientID;
hiddenInput.Nam e = UniqueID;
hiddenInput.Val ue = SelectedScopeID .ToString();
hiddenInput.Ren derControl(writ er);
}

When I look at the value of UniqueID inside the Render method, it has
colons in it, but for some reason, the name is being rendered to the
page using underscores instead. This, of course, causes my
LoadPostData method to fail, since the postDataKey has colons, not
underscores. Anyone have any idea why this could be happening?

Aug 4 '06 #1
3 2130
I have discovered the solution to this problem, but not the cause.
This behavior is in Framework 1.1, by the way, and it appears to be a
bug, though I'd like someone from Microsoft to confirm this.

In my control, I am trying to use a HtmlInputHidden control as a proxy
for a more complex control, so that no matter how I choose to render
the control, I will always have a single value come back. I create the
HtmlInputHidden control on PreRender, and then inside the Render
method, I render the other controls by hand and then pass the
HtmlTextWriter to the RenderControl method of the HtmlInputHidden
object.

In order to have things work correctly, I set the ID of the
HtmlInputHidden control to the surrounding control's ClientID, and the
name of the HtmlInputHidden control to the control's UniqueID, just as
I supposed I would have to. But strangely, when it rendered the
control, it rendered the ClientID to both attributes like this:
<input name="ucSearchF ilters_scope" id="ucSearchFil ters_scope"
type="hidden" value="-1" />

This, of course, will break the LoadPostData method, because the
postDataKey passed to it is "ucSearchFilter s:scope" (with a colon), but
the name of the control is "ucSearchFilter s_scope" (with an
underscore).

After experimenting with the HtmlInputHidden control a bit, I
discovered that once I set the ID on the control, then it copies this
value to the Name and will not allow it to be changed. So if you try
to set the Name after setting the ID, it will simply ignore the change.

If you do not set the ID at all, even if you set the name, it renders
like so:
<input name type="hidden" value="-1" />

This may or may not be valid HTML (I know that at least old versions of
HTML do not require attributes to have values, e.g. nowrap), but since
it has no ID, it is invisible to standard ECMA/JavaScript, and its
value will not be posted back because it has no Name.

This appears to be the behavior with any controls that do not have an
ID set. For example, on PreRender, I generated a DropDownList control
with no ID and then just called RenderControl on it, passing through
the HtmlTextWriter at render time. This displayed the same behavior:
<select name... </select>

The workaround to my particular problem is to set the
HtmlInputHidden .ID to the control's UniqueID -- which seems wrong,
since the UniqueID should be used as a name, not an ID, and ClientID
should be used as the ID. But inexplicably, when you set the ID to the
value of your containing control's UniqueID, it all renders correctly:
<input name="ucSearchF ilters:scope" id="ucSearchFil ters_scope"
type="hidden" value="-1" />

I hope this helps someone else who may have been banging their head
against a wall. Can someone confirm whether this is a bug?

dc*****@cmcdata works.com wrote:
I am working on a complex server control that dynamically creates an
HtmlInputHidden control that stores its value. As far as the postback
process is concerned, this hidden input acts as the control itself. So
when I render, I generate a proxy HtmlInputHidden like so:

protected virtual void Render(HtmlText Writer writer)
{
HtmlInputHidden hiddenInput = new HtmlInputHidden ();
hiddenInput.ID = ClientID;
hiddenInput.Nam e = UniqueID;
hiddenInput.Val ue = SelectedScopeID .ToString();
hiddenInput.Ren derControl(writ er);
}

When I look at the value of UniqueID inside the Render method, it has
colons in it, but for some reason, the name is being rendered to the
page using underscores instead. This, of course, causes my
LoadPostData method to fail, since the postDataKey has colons, not
underscores. Anyone have any idea why this could be happening?
Aug 4 '06 #2
In article <11************ *********@m79g2 000cwm.googlegr oups.com>,
dc*****@cmcdata works.com writes
>But strangely, when it rendered the control, it rendered the ClientID
to both attributes like this: <input name="ucSearchF ilters_scope"
id="ucSearchFi lters_scope" type="hidden" value="-1" />

This, of course, will break the LoadPostData method, because the
postDataKey passed to it is "ucSearchFilter s:scope" (with a colon), but
the name of the control is "ucSearchFilter s_scope" (with an underscore).
Don't know about the rest of your woes, but the reason for this is very
simple. Colons are not valid in element IDs. In order to produce valid
XHTML, colons are replaced by underscores. This is not a bug, this is by
design to produce valid XHTML.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)
Aug 8 '06 #3
Alan:

The problem is that the behavior is inconsistent. Names should use
colons and IDs should use underscores. Name attributes should map to
the UniqueID property; ID attributes should map to the ClientID
property. However, this is not what is happening.

Dan

Alan Silver wrote:
In article <11************ *********@m79g2 000cwm.googlegr oups.com>,
dc*****@cmcdata works.com writes
But strangely, when it rendered the control, it rendered the ClientID
to both attributes like this: <input name="ucSearchF ilters_scope"
id="ucSearchFil ters_scope" type="hidden" value="-1" />

This, of course, will break the LoadPostData method, because the
postDataKey passed to it is "ucSearchFilter s:scope" (with a colon), but
the name of the control is "ucSearchFilter s_scope" (with an underscore).

Don't know about the rest of your woes, but the reason for this is very
simple. Colons are not valid in element IDs. In order to produce valid
XHTML, colons are replaced by underscores. This is not a bug, this is by
design to produce valid XHTML.

HTH

--
Alan Silver
(anything added below this line is nothing to do with me)
Aug 14 '06 #4

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

Similar topics

9
8147
by: Josh Mayfield | last post by:
Note: There is considerable background detail here, but I do have three questions, which are clearly marked and appear right before the sample code. I have a legitimate need to launch an EXE from an HTML page on Windows XP/Internet Explorer. The EXE is already locally installed, and the HTML page is also viewed locally on the PC- it's not a web site. I know of two ways to do this, both of which are featured in the sample HTML file at...
6
6159
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but my mappings between named colors, HEX values and the Long Integer values used in Access are not jibbing. Anyone have a nice list laying around? Danny J Lesandrini dlesandrini@hotmail.com
0
1924
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. Chris. code :
2
8401
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 submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
17
2485
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control 'Button19' of type 'Button' must be placed inside a form tag with runat=server Can the IDE not do what it is supposed to do. It seems that it is a fight to make it do anything or did I do something wrong? It would seem silly to have to create a...
2
1026
by: Ralph Krausse | last post by:
I know more html is needed to really produce this but enough is here for me to ask my question. So, this HTML code produce 2 buttons. One button is a HTML control and the other is ASP Web or Server Control. Why are there 2 ways to create buttons if they so the same thing? Do they do the same thing? In what senario would I use a HTML button rather than a Web control button. Does it matter? If not why 2 different controls that do the same...
4
4220
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and webpage etc.. To Avoid having 1 ASP.Net application running for each client I am attempting a more...
4
2001
by: Sathyaish | last post by:
I am no JavaScript progammer, and unfortunately am having to babysit an old code base that has a lot of JavaScript in it. I have two questions: (1) Can two HTML controls have the same name? It looks like the obvious answer is NO. (2) What if? What if the developer has given two HTML controls the same name, i.e has created the same button more than once with exactly the
11
3147
by: saurabh | last post by:
Can anybody tell me how to change the value of an html control from the c#.... eg i hv one asp.net radio button control and one html hidden variable... so on page load in case the radio button is checked i want to set this hidden variable to 1 else 0... I am not getting what to write in Page_Load(object sender, System.EventArgs e) function to change the value of this html variable...
0
8872
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8747
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9246
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9162
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8069
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5997
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3211
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.