ralphtrent
Programmer
Hello
I am trying to take advantage of adding user controls on the fly to save duplicate code.
I have three controls that are added to the page in the Page_Init function. IT looks like this
The gUcNotify allows users to add or remove options. When a user removes options and a post back is fired, when the page reloads,the origional state of the control is loaded.
Any way to avoid this? I can not add
before the meat of the function because then the controls will not get added at all and the page will look empty.
I am putting this code in Page_Init as opposed to Page_Load because MSDN says
Thanks,
RalphTrent
I am trying to take advantage of adding user controls on the fly to save duplicate code.
I have three controls that are added to the page in the Page_Init function. IT looks like this
Code:
protected void Page_Init()
{
if (Request.QueryString.HasKeys())
{
gstNotifyType = Convert.ToString(Request.QueryString["NotifyType"]);
}
if (gstNotifyType != String.Empty)
{
/* load titelDesc control */
gUcTitleDesc = (uCtrlTitleDesc)this.LoadControl("~/Controls/global/TitleDesc.ascx");
gUcTitleDesc.ID = "gUcTitleDesc";
/* load notification control */
Label lblSelectOptions = new Label();
lblSelectOptions.ID = "lblSelectOptions";
lblSelectOptions.Text = "<h4>Select your options.</h4>";
gUcNotify = (uCtrlNotify)this.LoadControl("~/Controls/notifications/" + gstNotifyType + ".ascx");
gUcNotify.ID = "gUcNotify";
/* load schedule control */
gUcSchedule = (uCtrlScheudule)this.LoadControl("~/Controls/global/Schedule.ascx");
gUcSchedule.ID = "gUcSchedule";
phUserControl_Notifcation.Controls.Add(lblSelectOptions);
phUserControl_TitleDesc.Controls.Add(gUcTitleDesc);
phUserControl_Notifcation.Controls.Add(gUcNotify);
phUserControl_Schedule.Controls.Add(gUcSchedule);
this.LoadComplete += new EventHandler(wFrmNotificationManage_LoadComplete);
}
else
{
throw new Exception("No Notificaiton type was specified");
}
}
The gUcNotify allows users to add or remove options. When a user removes options and a post back is fired, when the page reloads,the origional state of the control is loaded.
Any way to avoid this? I can not add
Code:
if (!Page.IsPostBack)
I am putting this code in Page_Init as opposed to Page_Load because MSDN says
MSDN said:When you load a control into a container control, the container raises all of the added control's events until it has caught up to the current event. However, the added control does not catch up with postback data processing. For an added control to participate in postback data processing, including validation, the control must be added in the Init event rather than in the Load event.
Thanks,
RalphTrent