473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Custom Control does not allow access to Attributes

I built a custom control for all the basic web.ui.controls like textbox,
label, checkbox etc etc. I added my custom attribute called ApplySecurity to
the html in the page.

However, when I cycle through the controls on the page using this code, I
cant seem to be able to access the Attribute collection. However, if I were
to add the tag to a regular TextBox, the Attribute is available.

My recursive function looks like this:
************************************************** *****
private SortedList PageFieldDetector(Control ctlPage, ref SortedList
r_slPageControlList)

{

string strPageID = ctlPage.ClientID;

string strObjectID = "";

string strObjectType = "";

string strTempObjectType = "";

string strApplySecurity = "";

int intLastPeriodIndexPosition = 0;

foreach (Control ctrl in ctlPage.Controls)

{

strObjectID = ctrl.ClientID.ToString();

//check if securable

try

{

strApplySecurity =
((WebControl)(ctrl)).Attributes["applysecurity"].ToString();

}

catch

{

strApplySecurity = "False";

}

if (strApplySecurity == "True")

{

strTempObjectType = ctrl.GetType().ToString();

intLastPeriodIndexPosition = strTempObjectType.LastIndexOf(".") + 1;

strObjectType = strTempObjectType.Substring(intLastPeriodIndexPosi tion,
strTempObjectType.Length - intLastPeriodIndexPosition);

r_slPageControlList.Add(strObjectID, strObjectType);

}

else

{

if (ctrl.Controls.Count > 0)

{

PageFieldDetector(ctrl, ref r_slPageControlList);

}

}

}

return r_slPageControlList;

}

************************************************** *****
A regular html control like this has the attribute collection:
<asp:Label ID="lblHeader" applysecurity="False" runat="server" Text="Page
Header No security is to be applied to this object"></asp:Label>

However, My custom textbox does not diaplay any attributes at all

<aepc:aeptextbox id="AEPTextBox1" runat="server"
applysecurity="True"></aepc:aeptextbox>

This is my code for the custom textbox:

using System;

using System.Collections.Generic;

using System.Text;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

using System.Drawing;

using System.Diagnostics;

using System.Design;

[assembly: TagPrefix("AEPortal", "AEPC")]

namespace AEPortal

{

[ToolboxData("<{0}:AEPTextBox runat=server
applysecurity=False></{0}:AEPTextBox>")]

[ToolboxBitmap(typeof(TextBox))]

[DesignerAttribute("System.Web.UI.WebControls.TextB ox")]

public class AEPTextBox : System.Web.UI.WebControls.TextBox

{

[Bindable(true),

Description("Accruent Enterprise Portal Custom TextBox"),

Category("Misc"),

DefaultValue("False")]

private bool blnApplySecurity = false;

public bool ApplySecurity

{

get

{

return blnApplySecurity;

}

set

{

blnApplySecurity = value;

}

}

protected override void Render(HtmlTextWriter w)

{

w.AddAttribute("applysecurity", blnApplySecurity.ToString());

base.Render(w);

}

}

}
Nov 19 '05 #1
1 1677
Arbitrary attributes (ones where there is no property) are implemented by
the custom control implementing the IAttributeAccessor interface.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I built a custom control for all the basic web.ui.controls like
textbox, label, checkbox etc etc. I added my custom attribute called
ApplySecurity to the html in the page.

However, when I cycle through the controls on the page using this
code, I cant seem to be able to access the Attribute collection.
However, if I were to add the tag to a regular TextBox, the Attribute
is available.

My recursive function looks like this:
************************************************** *****
private SortedList PageFieldDetector(Control ctlPage, ref SortedList
r_slPageControlList)
{

string strPageID = ctlPage.ClientID;

string strObjectID = "";

string strObjectType = "";

string strTempObjectType = "";

string strApplySecurity = "";

int intLastPeriodIndexPosition = 0;

foreach (Control ctrl in ctlPage.Controls)

{

strObjectID = ctrl.ClientID.ToString();

//check if securable

try

{

strApplySecurity =
((WebControl)(ctrl)).Attributes["applysecurity"].ToString();

}

catch

{

strApplySecurity = "False";

}

if (strApplySecurity == "True")

{

strTempObjectType = ctrl.GetType().ToString();

intLastPeriodIndexPosition = strTempObjectType.LastIndexOf(".") + 1;

strObjectType =
strTempObjectType.Substring(intLastPeriodIndexPosi tion,
strTempObjectType.Length - intLastPeriodIndexPosition);

r_slPageControlList.Add(strObjectID, strObjectType);

}

else

{

if (ctrl.Controls.Count > 0)

{

PageFieldDetector(ctrl, ref r_slPageControlList);

}

}

}

return r_slPageControlList;

}

************************************************** *****
A regular html control like this has the attribute collection:
<asp:Label ID="lblHeader" applysecurity="False" runat="server"
Text="Page
Header No security is to be applied to this object"></asp:Label>
However, My custom textbox does not diaplay any attributes at all

<aepc:aeptextbox id="AEPTextBox1" runat="server"
applysecurity="True"></aepc:aeptextbox>

This is my code for the custom textbox:

using System;

using System.Collections.Generic;

using System.Text;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

using System.Drawing;

using System.Diagnostics;

using System.Design;

[assembly: TagPrefix("AEPortal", "AEPC")]

namespace AEPortal

{

[ToolboxData("<{0}:AEPTextBox runat=server
applysecurity=False></{0}:AEPTextBox>")]

[ToolboxBitmap(typeof(TextBox))]

[DesignerAttribute("System.Web.UI.WebControls.TextB ox")]

public class AEPTextBox : System.Web.UI.WebControls.TextBox

{

[Bindable(true),

Description("Accruent Enterprise Portal Custom TextBox"),

Category("Misc"),

DefaultValue("False")]

private bool blnApplySecurity = false;

public bool ApplySecurity

{

get

{

return blnApplySecurity;

}

set

{

blnApplySecurity = value;

}

}

protected override void Render(HtmlTextWriter w)

{

w.AddAttribute("applysecurity", blnApplySecurity.ToString());

base.Render(w);

}

}

}


Nov 19 '05 #2

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

Similar topics

1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
3
by: Edward Diener | last post by:
I understand the syntax of custom attributes, but I have no idea what they are supposed to do. Anyone care to give me a clue as to their functionality ?
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
3
by: The Developer | last post by:
Hi All, I have a web application where I am adding a custom attribute to my ASP.NET text box control and changing value of that attribute at client side using JavaScript. My problem is that...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
2
by: J R M | last post by:
I've developed a custom control (it's basically a drop-down list and then a couple of textboxes to include meta-data for the selection) that I'm embedding into another custom control (the idea is...
2
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.