I have defined class customtextbox inherits webcontol and implement IPostBackDataHandler, it contain all properties and render method.
I have wired the
OnTextChanged
event and wired it to my custom control like this:
Page.Page.RegisterRequiresPostBack(CustomTextBox1);
Is this a correct way to call?
My doubt is that the parameter inside the method represent correct way or should I change to anything else.
I am not getting my posted back data in text box to my custom page.
My aspx page:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (Page != null)
{
Page.RegisterRequiresRaiseEvent(CustomImageButton1);
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
My custom sever control page:
public class CustomTextBox : WebControl,IPostBackDataHandler
{
public string Text
{
get
{
String s = (String)ViewState["Text"];
return s;
}
set
{
ViewState["Text"] = value;
}
}
public CustomTextBox() : base(HtmlTextWriterTag.Input)
{
Text = " ";
}
public event EventHandler TextChanged;
protected override void RenderContents(HtmlTextWriter output)
{
output.AddAttribute(HtmlTextWriterAttribute.Type, "text");
output.AddAttribute(HtmlTextWriterAttribute.Value, Text);
output.AddAttribute("name", this.UniqueID);
base.AddAttributesToRender(output);
}
public bool LoadPostData(string postDataKey, NameValueCollection postData)
{
string postedValue = postData[postDataKey];
string s = postData[0];
string viewstateValue = Text;
if (viewstateValue != postedValue)
{
Text = postedValue;
return true;
}
else
{
return false;
}
}
public void RaisePostDataChangedEvent()
{
OnTextChanged(new EventArgs());
}
protected virtual void OnTextChanged(EventArgs e)
{
if (TextChanged != null)
TextChanged(this, e);
}
Appreciation in advance