Andrew Stevenson's WebLog

Write Here Write Now

Syndication

.Net Languages

ADO.Net

Asp.Net (Misc.)

Asp.Net Controls

Bad Patterns

Err What?

Files and Folders

Forums

IE Add-Ins

Methods for the Madness

Performance

See Clearer, C#

Test Driven

IExtenderProvider & Asp.Net

I've implemented a simple extender following the example here.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcomponentmodelprovidepropertyattributeclasstopic.asp

I've used a string property instead of the CultureInfo from the example. When I change the value on the design surface, the SetXX method is called with the correct control, but when I look at the code that is serialized into InitializeComponent it uses "this" which is the page, rather than "this.Label1".

I am wondering if there is a better example of an extender with WebControls, if I am doing something silly, if it would work if I were at work and using VS 2003 instead of  being at home with VS 2002, how many people are gonna blast me for posting this here instead of in some newsgroup where 12 people will aske me if this has answered my question ;)

this.webControlExtender1.SetLocalizationKey(this, "dfsdfsd");
 
using
System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.ComponentModel;

[ProvideProperty("MyProperty",
typeof(Control))]
[ProvideProperty("LocalizationKey",
typeof(Control))]
public class WebControlExtender :Control, IExtenderProvider
{
public WebControlExtender()
{

}
public bool CanExtend(object target)
{

return (target is Control);
}
private string _testString ="";
public string GetLocalizationKey(Control control)
{
return _testString;
}
public void SetLocalizationKey(Control control,string value)
{
System.Windows.Forms.MessageBox.Show(control.ID);
_testString =
value;
}
}

Update:
I'm saving to the html attributes for now.
I would really like to save property values I add to a WebControl into the resx the same way that properties I add to a component are saved.

public void SetQuestionID(WebControl control,string value)

{

if(value.Length >0 )
{
control.Attributes[AttributeQuestionID] =
value;
}
else
{
control.Attributes.Remove(AttributeQuestionID);
}
ComponentChanging(control);

}

Published Friday, June 25, 2004 12:26 PM by AndrewSeven

Filed under:

Comments

No Comments