Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > WebControl.Attributes.Add and custom attributes

Reply
Thread Tools

WebControl.Attributes.Add and custom attributes

 
 
P4trykx
Guest
Posts: n/a
 
      01-31-2007
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

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      01-31-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      01-31-2007
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
data attributes override method attributes? Jayden Python 16 09-29-2012 03:20 AM
attributes ala java annotations or .Net attributes? Kyle Schmitt Ruby 3 07-24-2007 07:48 PM
class attributes & data attributes james_027 Python 2 06-20-2007 03:12 PM
Parse reserved attributes as normal attributes Max XML 1 09-22-2006 12:04 PM
Custom TextBox with custom attributes and properties question John Wright ASP .Net Building Controls 1 03-01-2004 02:01 PM



Advertisments