473,605 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebControl.Attr ibutes.Add and custom attributes

Hello
I'm want to add some custom attributes to WebControls using
WebControl.Attr ibutes.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.Att rbites.Add("abc ","1");

JS
document.GetEle mentById("someT extBox").abc = "0" ;

here goes the psotabck on server

C#
someTextBox.Att rbites["abc"] == "1"
Patryk

Jan 31 '07 #1
2 13855
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**********@g mail.comwrote in message
news:11******** **************@ a34g2000cwb.goo glegroups.com.. .
Hello
I'm want to add some custom attributes to WebControls using
WebControl.Attr ibutes.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.Att rbites.Add("abc ","1");

JS
document.GetEle mentById("someT extBox").abc = "0" ;

here goes the psotabck on server

C#
someTextBox.Att rbites["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="fo o">

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.getEle mentById('c1'). value

notice you have to use "value", even though it was specified "Value". in
javascript you can also add a dynamic property:

document.getEle mentById('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.getEle mentById('c1'). getAttribute('m yattribute');

to create one:

document.getEle mentById('c1'). getAttribute('V alue')='attvalu e';

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.Attr ibutes.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.Att rbites.Add("abc ","1");

JS
document.GetEle mentById("someT extBox").abc = "0" ;

here goes the psotabck on server

C#
someTextBox.Att rbites["abc"] == "1"
Patryk
Jan 31 '07 #3

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

Similar topics

0
1757
by: Harry F. Harrison | last post by:
Here's the situation...Context - Using an Inherited WebControl object as a base for server custom controls. In a web custom control, whenever I create a child control and add it to the Controls class, it takes 3 lines of code. Example: Dim TextBox as System.Web.UI.WebControls.TextBox 1..TextBox = New System.Web.UI.WebControls.TextBox
9
2659
by: kw | last post by:
What is the proper way to get the element ID for a client script? For example, suppose in the WebControl: TextBox t=new TextBox; t.ID=this.ClientID+"X"; .... Then elsewhere we want to access it on the client: Control.Attributes = "javascript:document.getElementById('"+this.ClientID+"X"+"').value= 'test';";
2
5909
by: Novice | last post by:
I can't seem to get my Custom WebControl to output a button whose click event is associated with a particular method. Here is the code I have right now that contains a panel and there is a button in that panel that should be associated with a event method - but it isn't working: protected override void Render(HtmlTextWriter output) { Panel panel = new Panel(); nextButton = new Button();
1
2267
by: Peter | last post by:
I have a dilemna. Currently I have created a custom calendar webcontrol that a user can select and will dump the date along with some specialized information set in the tooltip. It actually is working great. However I am having the same second thoughts about the control as everyone else because of all the real estate it takes up so I would like to add a button to alternately hide/display the calendar control. The only problem is that if I...
0
2939
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
0
2018
by: Dariusz Tomon | last post by:
Hi I have got the problem with web control displaying flash (swf) object. The problem is connected with the fact that 1-st swf should loads the second one. But it doesn't. That's why I suspects taht webcontrol or class under it causes that problem. Maybe the following code is too long to analyze so pls redirect me whare I could read/download the code suitable for that purposes.
2
2535
by: Peter Rilling | last post by:
Okay, I something weird is happening where I do not know if I am doing something wrong. I have a page that contains a custom webcontrol that I developed. This webcontrol basically loads a UserControl (ascx) using the LoadControl method and writing it out to the browser. Page --> custom webcontrol --> usercontrol (via LoadControl) --> stream to browser.
3
5698
by: Tomasz J | last post by:
Hello Developers, How do create a custom WebControl (not UserControl), exposing OnClick event? I reviewed countless examples found by Google, but came across nothing helpful. Below I attach what I got so far. Thank you for any hints. Tomasz J
2
1779
by: Brook | last post by:
In webform.aspx: <cc:ctlB ID="ctl1" runat="server" Width="200px" /> If set value to width property, I will get a error that say ctlB.Page is null. This control will be fine with no width property, why? Could anybody help me ? thanks ctlA.cs ----------------------------
0
8004
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
7934
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
8425
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
8288
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6743
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
5445
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
3912
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
1541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1271
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.