473,803 Members | 3,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems using GetAttribute and SetAttribute of the IAttributeAcces sor interface with web controls

Hiya,

I'm trying to replace the commented out code below with a neater
version using the IAttributeAcces sor interface (so that I don't have to
write 'if' statements for all control types).

At the moment this doen't work. The test line I put in

(string s = ControlAttribut es.string s = ControlAttribut es.GetAttribute
("Text");

is giving me s as null. Neither the GetAttribute nor the SetAttrubute
fail - they just don't seem to do anything.

Any clues what I'm doing wrong?

Kirsty
_______________ _______________ _____

public void SetCaptions
(
System.Web.UI.H tmlControls.Htm lForm WebForm,
System.Data.Dat aSet Captions
)
{
System.Data.Dat aTable CaptionDataTabl e = new System.Data.Dat aTable();
string ControlName = "";
string ControlText = "";
System.Web.UI.C ontrol Control;

// Get the captions data table from the dataset
CaptionDataTabl e = Captions.Tables[_CaptionDataTab leName];

// Go through the data, setting the Text property of each control
foreach (System.Data.Da taRow Row in CaptionDataTabl e.Rows)
{
ControlName = Row[_ControlNameFie ldName].ToString();
ControlText = Row[_ControlCaption FieldName].ToString();
Control = WebForm.FindCon trol (ControlName);

if (!(Control == null))
{
System.Web.UI.I AttributeAccess or ControlAttribut es =
(System.Web.UI. IAttributeAcces sor)Control;
string s = ControlAttribut es.GetAttribute ("Text");
ControlAttribut es.SetAttribute ("Text",Control Text);
// if (Control is System.Web.UI.W ebControls.Labe l)
// {
// System.Web.UI.W ebControls.Labe l Lbl =
(System.Web.UI. WebControls.Lab el)Control;
// Lbl.Text = ControlText;
// } // (ControlType is System.Web.UI.W ebControls.Labe l)

} //(!(Control ==null))
} //foreach

} //SetCaptions

Nov 19 '05 #1
3 3478
From the help page for IAttributeAcces sor

http://msdn.microsoft.com/library/de...classtopic.asp

"Defines methods used by ASP.NET server controls to provide programmatic
access to any attribute declared in the opening tag of a server control."

If you were too look at your label control that was rendered to the browser
you would probably see

<span Text=""></span>

When you are calling the GetAttribute( "Text" ) there is not a client side
text attribute defined yet.

To accomplish this you will need to use reflection.

Control = WebForm.FindCon trol (ControlName);

if ( Control != null ) {
Type t = Control.GetType ();
System.Reflecti on.PropertyInfo info = t.GetProperty( "Text" ); //gets the
property called Text if it exists on the control.

if ( info != null ) //this will actually set the Text property of all
controls that have one
info.SetValue( Control, LabelText, null );
}

You are confusing client side attributes with class properties.

HTH,

bil

<du**@netcomuk. co.uk> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hiya,

I'm trying to replace the commented out code below with a neater
version using the IAttributeAcces sor interface (so that I don't have to
write 'if' statements for all control types).

At the moment this doen't work. The test line I put in

(string s = ControlAttribut es.string s = ControlAttribut es.GetAttribute
("Text");

is giving me s as null. Neither the GetAttribute nor the SetAttrubute
fail - they just don't seem to do anything.

Any clues what I'm doing wrong?

Kirsty
_______________ _______________ _____

public void SetCaptions
(
System.Web.UI.H tmlControls.Htm lForm WebForm,
System.Data.Dat aSet Captions
)
{
System.Data.Dat aTable CaptionDataTabl e = new System.Data.Dat aTable();
string ControlName = "";
string ControlText = "";
System.Web.UI.C ontrol Control;

// Get the captions data table from the dataset
CaptionDataTabl e = Captions.Tables[_CaptionDataTab leName];

// Go through the data, setting the Text property of each control
foreach (System.Data.Da taRow Row in CaptionDataTabl e.Rows)
{
ControlName = Row[_ControlNameFie ldName].ToString();
ControlText = Row[_ControlCaption FieldName].ToString();
Control = WebForm.FindCon trol (ControlName);

if (!(Control == null))
{
System.Web.UI.I AttributeAccess or ControlAttribut es =
(System.Web.UI. IAttributeAcces sor)Control;
string s = ControlAttribut es.GetAttribute ("Text");
ControlAttribut es.SetAttribute ("Text",Control Text);
// if (Control is System.Web.UI.W ebControls.Labe l)
// {
// System.Web.UI.W ebControls.Labe l Lbl =
(System.Web.UI. WebControls.Lab el)Control;
// Lbl.Text = ControlText;
// } // (ControlType is System.Web.UI.W ebControls.Labe l)

} //(!(Control ==null))
} //foreach

} //SetCaptions

Nov 19 '05 #2
thats because the Text property of a Label is not an attribute. if you look
at the rendered html, you should see something like:

<span Text="valueOf Controltext" id="labelname"> </span>

where your code added the Text attribute (meanless to the browser)

-- bruce (sqlwork.com)
<du**@netcomuk. co.uk> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hiya,

I'm trying to replace the commented out code below with a neater
version using the IAttributeAcces sor interface (so that I don't have to
write 'if' statements for all control types).

At the moment this doen't work. The test line I put in

(string s = ControlAttribut es.string s = ControlAttribut es.GetAttribute
("Text");

is giving me s as null. Neither the GetAttribute nor the SetAttrubute
fail - they just don't seem to do anything.

Any clues what I'm doing wrong?

Kirsty
_______________ _______________ _____

public void SetCaptions
(
System.Web.UI.H tmlControls.Htm lForm WebForm,
System.Data.Dat aSet Captions
)
{
System.Data.Dat aTable CaptionDataTabl e = new System.Data.Dat aTable();
string ControlName = "";
string ControlText = "";
System.Web.UI.C ontrol Control;

// Get the captions data table from the dataset
CaptionDataTabl e = Captions.Tables[_CaptionDataTab leName];

// Go through the data, setting the Text property of each control
foreach (System.Data.Da taRow Row in CaptionDataTabl e.Rows)
{
ControlName = Row[_ControlNameFie ldName].ToString();
ControlText = Row[_ControlCaption FieldName].ToString();
Control = WebForm.FindCon trol (ControlName);

if (!(Control == null))
{
System.Web.UI.I AttributeAccess or ControlAttribut es =
(System.Web.UI. IAttributeAcces sor)Control;
string s = ControlAttribut es.GetAttribute ("Text");
ControlAttribut es.SetAttribute ("Text",Control Text);
// if (Control is System.Web.UI.W ebControls.Labe l)
// {
// System.Web.UI.W ebControls.Labe l Lbl =
(System.Web.UI. WebControls.Lab el)Control;
// Lbl.Text = ControlText;
// } // (ControlType is System.Web.UI.W ebControls.Labe l)

} //(!(Control ==null))
} //foreach

} //SetCaptions

Nov 19 '05 #3
k
Thanks to you both for correcting my bit of Friday afternoon confusion.

Kirsty

Nov 19 '05 #4

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

Similar topics

2
4446
by: Jon Dellaria | last post by:
I have been using MySql as the database using JSP's and JavaBeans but recently I have wanted to start using the database connection pooling mechanism built into TomCat. I think I am having a problem with defining my JDBC resource within Tomcat. I am pretty sure that my code is correct (but I am not certain), and the problem is with defining the resource in Tomcat. Has anyone done this before? Any advice would be helpful.
3
3165
by: daveland | last post by:
I am working on some JavaScript that dynamically adds rows to a table in response to a button click. A new row does appear on the screen when the button is clicked. However, that table to which a row has been added is itself contained within an outer table (to handle the desired screen layout). That outer table does not properly grow to contain the new size of the table to which the row was added. (More specifically, I have...
14
2000
by: hgraham | last post by:
Hi, I'm trying to understand how to work the dom, and all I'm trying to do is insert a link right before another link in the html based on it's href value. This isn't a real world example - I'm just trying to do this in phases to understand what's going on. I'm getting an error (Object doesn't support this property or method) in IE and I can't figure out what I'm doing wrong. Can anyone tell me? if (navigator.appName == "Microsoft...
10
4282
by: webEater | last post by:
Hello, I try the following in Firefox and other modern browsers: window.addEventListener('load', function() { document.title = CSS.getClass('fontSize'); var div = document.createElement('div'); document.getElementsByTagName('body').appendChild(div); alert(div); alert(div.style) }, true);
4
5057
by: ICPooreMan | last post by:
I've got some code which works in firefox that's giving me fits in IE7 (maybe other versions too I haven't tested it). What I want to do is get the oncontextmenu attribute of something, change the value then put it back as the oncontextmenu attribute. Here's an example page if you want to try it out... <html> <head> <titletesting </title> <script><!--
7
3650
by: petethebloke | last post by:
Can anyone help? I have a client who has made a "dynamic interactive map" of our city using Dreamweaver. Each map file has hotspots that pop-up a div with a little image when the mouse goes over them. They also link to another file. I've converting the application to a PHP-AJAX system at http://www.ilex-urc-maps.com/testing.html but I can't get the dynamically altered hotspots to work. Any ideas? Please don't tell me that the client...
7
1772
evilmonkey
by: evilmonkey | last post by:
My assignment was to create a shopping cart servlet, it works locally on tomcat but when I deploy it to the schools server (also tomcat) it fails to refresh the front page and just prints the HTML Code not the page. Any thoughts or a helping hand would be appreciated. import java.io.*; import java.net.*; import java.text.NumberFormat; import java.util.*; import javax.servlet.*; import javax.servlet.http.*;
3
2560
by: maminx | last post by:
I have this script... var td = document.createElement('td'); var p = document.createElement('p'); var label = document.createElement('label'); var span = document.createElement('span'); var theData = document.createTextNode('Chart Of Account'); var theSelect = document.createElement('select'); theSelect.setAttribute('name', 'items'); var opCol = document.createElement('option');
0
9699
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
10542
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
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9119
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...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6840
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
5496
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
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.