Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Solel Software #1
Newbie IPostBackDataHandler Question
Hi,
I am having a problem with a custom server control I'm working on and put
together a skeleton example to demonstrate the problem. Basically, I have a
custom server control with two RadioButton controls added in
CreateChildControls. They work great and all is well except for some reason
their information is not available in IPostBackDataHandler.LoadPostData.
I've gone through the ViewState and the postCollection argument to
LoadPostData but haven't found the radio buttons' information there either.
Is there something special that I have to do? For some reason, the
information is not being stored in ViewState so it is not a LoadViewState
issue (or maybe it is?). I _am_ able to access a TextBox and DropDownList's
information in IPostBackDataHandler.LoadPostData so it seems to affect only
RadioButton controls. The code for the bare-bones server control to
illustrate the problem is below. Any help would be appreciated! Thanks so
much!
--
Sincerely,
Mark Fox
public class TestRadio : System.Web.UI.Control, IPostBackDataHandler,
INamingContainer
{
public TestRadio() : base() {}
#region Implementation of IPostBackDataHandler
void IPostBackDataHandler.RaisePostDataChangedEvent()
{
}
bool IPostBackDataHandler.LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
// HERE IS THE PROBLEM: both the RadioButtons have Checked == false
// on postback even when one is selected
RadioButton rb1 = (RadioButton) Controls[0];
RadioButton rb2 = (RadioButton) Controls[1];
return false;
}
#endregion
#region Render Overrides
protected override void CreateChildControls()
{
#region rb1
_rb1 = new RadioButton();
_rb1.GroupName = "DateSet";
_rb1.CssClass = "Normal";
_rb1.Text = "1";
this.Controls.Add(_rb1);
#endregion rb1
#region rb2
_rb2 = new RadioButton();
_rb2.GroupName = "DateSet";
_rb2.CssClass = "Normal";
_rb2.Text = "2";
this.Controls.Add(_rb2);
#endregion rb2
}
protected override void Render( HtmlTextWriter writer )
{
this.EnsureChildControls();
base.Render(writer);
writer.AddAttribute(HtmlTextWriterAttribute.Type, "Hidden");
writer.AddAttribute(HtmlTextWriterAttribute.Value, "");
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
writer.RenderBeginTag(HtmlTextWriterTag.Input);
writer.RenderEndTag();
}
#endregion
protected internal RadioButton rb1
{
get { EnsureChildControls(); return _rb1; }
}
protected internal RadioButton rb2
{
get { EnsureChildControls(); return _rb2; }
}
private RadioButton _rb1;
private RadioButton _rb2;
}
Solel Software Guest
-
Newbie Question: Biz Card Template Question
Hi, I got the Pagemaker PlugIn - I am using one of the templates for Business Cards - the elements appear to be grouped (bound box all around when I... -
IPostBackDataHandler not working properly with DataGrid
Hello All, I've posted this in microsoft.public.dotnet.framework.aspnet.datagridcontrol but got not reply so I'll try my luck here. Any... -
System.OverflowException during IPostBackDataHandler.LoadPostData
During my postbacks, I try to assign the value from an Input tag to a property of a custom control. However, I keep recieving the following error: ... -
Pen Tool Use Question. (Embarrassingly Newbie Question)
I'm currently using Flash MX and whenever I choose the Pen Tool instead of the pen nib with the small "x" beside it that supposed to show up on... -
Help w/ IPostBackDataHandler
Your sample still leaves me confused. Can i email you offlist? "Natty Gur" <natty@dao2com.com> wrote in message... -
Solel Software #2
RE: Newbie IPostBackDataHandler Question
I figured this out. You don't have to reply, but thanks for looking!
It turns out the info is posted back in the postCollection just not in a
normal format (and for some reason it isn't in ViewState and is not loaded up
by ASP.NET). It has to be parsed. The value in
postCollection[this.UniqueID + ":" + this.GroupName]
is the UniqueID of the radio button that is selected. So I added the
following to IPostBackDataHandler.LoadPostData
string postCollectionRadioButtonKey = this.UniqueID + ":" + this.GroupName;
string postedValue = postCollection[postCollectionRadioButtonKey];
if(postedValue != null)
{
foreach(Control thisControl in Controls)
{
if(thisControl.UniqueID == postedValue)
{
// this is the radio button that is checked,
// the ID is null so you have to check another
// property such as
// ((RadioButton) thisControl).Text
}
}
}
"Solel Software" wrote:
> Hi,
>
> I am having a problem with a custom server control I'm working on and put
> together a skeleton example to demonstrate the problem. Basically, I have a
> custom server control with two RadioButton controls added in
> CreateChildControls. They work great and all is well except for some reason
> their information is not available in IPostBackDataHandler.LoadPostData.
> I've gone through the ViewState and the postCollection argument to
> LoadPostData but haven't found the radio buttons' information there either.
> Is there something special that I have to do? For some reason, the
> information is not being stored in ViewState so it is not a LoadViewState
> issue (or maybe it is?). I _am_ able to access a TextBox and DropDownList's
> information in IPostBackDataHandler.LoadPostData so it seems to affect only
> RadioButton controls. The code for the bare-bones server control to
> illustrate the problem is below. Any help would be appreciated! Thanks so
> much!
>
> --
> Sincerely,
>
> Mark Fox
>
> public class TestRadio : System.Web.UI.Control, IPostBackDataHandler,
> INamingContainer
> {
> public TestRadio() : base() {}
>
> #region Implementation of IPostBackDataHandler
> void IPostBackDataHandler.RaisePostDataChangedEvent()
> {
> }
>
> bool IPostBackDataHandler.LoadPostData(string postDataKey,
> System.Collections.Specialized.NameValueCollection postCollection)
> {
> // HERE IS THE PROBLEM: both the RadioButtons have Checked == false
> // on postback even when one is selected
> RadioButton rb1 = (RadioButton) Controls[0];
> RadioButton rb2 = (RadioButton) Controls[1];
>
> return false;
> }
> #endregion
>
> #region Render Overrides
> protected override void CreateChildControls()
> {
> #region rb1
> _rb1 = new RadioButton();
> _rb1.GroupName = "DateSet";
> _rb1.CssClass = "Normal";
> _rb1.Text = "1";
> this.Controls.Add(_rb1);
> #endregion rb1
>
> #region rb2
> _rb2 = new RadioButton();
> _rb2.GroupName = "DateSet";
> _rb2.CssClass = "Normal";
> _rb2.Text = "2";
> this.Controls.Add(_rb2);
> #endregion rb2
> }
>
> protected override void Render( HtmlTextWriter writer )
> {
> this.EnsureChildControls();
> base.Render(writer);
> writer.AddAttribute(HtmlTextWriterAttribute.Type, "Hidden");
> writer.AddAttribute(HtmlTextWriterAttribute.Value, "");
> writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
> writer.RenderBeginTag(HtmlTextWriterTag.Input);
> writer.RenderEndTag();
> }
> #endregion
>
> protected internal RadioButton rb1
> {
> get { EnsureChildControls(); return _rb1; }
> }
> protected internal RadioButton rb2
> {
> get { EnsureChildControls(); return _rb2; }
> }
> private RadioButton _rb1;
> private RadioButton _rb2;
> }Solel Software Guest



Reply With Quote

