WebControl.Attributes.Add and custom attributes

Discussion in 'ASP .Net' started by P4trykx, Jan 31, 2007.

  1. P4trykx

    P4trykx Guest

    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
     
    P4trykx, Jan 31, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
     
    Eliyahu Goldin, Jan 31, 2007
    #2
    1. Advertising

  3. P4trykx

    bruce barker Guest

    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
    >
     
    bruce barker, Jan 31, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    742
  2. Luis Ramírez.

    Can a webcontrol (webcontrol.dll) have a configuration file?

    Luis Ramírez., Jul 5, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    207
    Luis Ramírez
    Jul 6, 2004
  3. Kasabaarde Sumta

    WebControl inside of WebControl and attaching events

    Kasabaarde Sumta, Dec 13, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    203
    Kasabaarde Sumta
    Dec 13, 2004
  4. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    191
    Fabricio
    Sep 21, 2005
  5. Curt_C [MVP]

    Custom WebControl, custom property list

    Curt_C [MVP], Sep 1, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    185
    Curt_C [MVP]
    Sep 1, 2005
Loading...

Share This Page