Re: WebControl.Attributes.Add and custom attributes
- From: bruce barker <nospam@xxxxxxxxxx>
- Date: Wed, 31 Jan 2007 08:33:49 -0800
you are confusing attributes with javascript properties. some html attributes are used to set properties. take the following html
<input Name="c1" id="c1" type="hidden" Value="value1" myattribute="foo">
when the browser parses the input node, it set properties for name, id, type and value attributes which have the same name (but in lowercase).
this you can reference the value by:
document.getElementById('c1').value
notice you have to use "value", even though it was specified "Value". in javascript you can also add a dynamic property:
document.getElementById('c1').Value = "myValue";
now the input has a "Value" and "value" property.
because the input is a dom object, it also has additional dom properties. attributes are accessed with dom methods and are not properties. to access an attribute:
document.getElementById('c1').getAttribute('myattribute');
to create one:
document.getElementById('c1').getAttribute('Value')='attvalue';
now the input has a 'Value' attribute distinct from the 'Value' property.
note: the browser only post back name/value pairs for form elements, so any attribute changes are not seen by the server.
-- bruce (sqlwork.com)
P4trykx wrote:
Hello.
I'm want to add some custom attributes to WebControls using
WebControl.Attributes.Add("abc","234");
So the html output will look like this,
<input type="hidden" abc="123" /> etc.
I know that I need to modify .dtd file and tell the browser that abc i
legal attribute.
But I have another problem, I can't change the abc attribute using
javascript, the change is invisible in code behind :-(. (in js it's
visible)
C#
someTextBox.Attrbites.Add("abc","1");
JS
document.GetElementById("someTextBox").abc = "0" ;
here goes the psotabck on server
C#
someTextBox.Attrbites["abc"] == "1"
Patryk
- References:
- WebControl.Attributes.Add and custom attributes
- From: P4trykx
- WebControl.Attributes.Add and custom attributes
- Prev by Date: Dynamically change display while processing a button click.
- Next by Date: Re: ASP.net variable assignment
- Previous by thread: Re: WebControl.Attributes.Add and custom attributes
- Next by thread: Timeout makes report fail
- Index(es):
Loading