471,595 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

WebControl.Attributes.Add and custom attributes

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

Jan 31 '07 #1
2 13654
You don't have to modify .dtd file, browser will accept the new attribute
just fine.

Asp.net doesn't take care of custom attributes automatically. You need to
pass their values by some other means, for example in hidden input elements.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"P4trykx" <pa**********@gmail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
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

Jan 31 '07 #2
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('myattr ibute');

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
Jan 31 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Peter | last post: by
reply views Thread by Demetri | last post: by
reply views Thread by Dariusz Tomon | last post: by
2 posts views Thread by Peter Rilling | last post: by
3 posts views Thread by Tomasz J | last post: by
reply views Thread by leo001 | last post: by

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.