PC Review


Reply
Thread Tools Rate Thread

Custom Control does not allow access to Attributes

 
 
Sanjay Pais
Guest
Posts: n/a
 
      11th Aug 2005
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(intLastPeriodIndexPosition,
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.TextBox")]

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);

}

}

}


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      11th Aug 2005
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(intLastPeriodIndexPosition,
> 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.TextBox")]
>
> 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);
>
> }
>
> }
>
> }
>




 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
How do you access a control property of a main form from a custom user control? forest demon Microsoft C# .NET 6 22nd Aug 2007 11:36 PM
WebControl.Attributes.Add and custom attributes P4trykx Microsoft ASP .NET 2 31st Jan 2007 04:33 PM
Cannot access custom attributes in Firefox / Opera cardalda@gmail.com Microsoft ASP .NET 1 25th Sep 2006 05:14 AM
Stage of a custom control's lifecycle that tag attributes are set Helen Microsoft ASP .NET 0 25th Oct 2004 12:04 PM
Want to control a Excel chart's attributes from Access Carolyn Schmidt Microsoft Access VBA Modules 1 31st Jul 2004 12:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:55 AM.