I am looking for a place to initialize some variables in an aspnet Wizard.
I want this stuff to be called 1 time. After the constructor has been set up.
I've tried Wizard1_PreRender and Wizard1_Init, in both cases they are called with each Wizard step.
Where is the correct place for my initialization?
TIA
Hi,
You can locate the intializing code in either Wizard_PreRender and Wizard_Init event.
The key point in this case is page's postback. As we know, when next step is called in Wizard control, the page will postback and in this process, the page will load Wizard again, and call the event like Wizard's Init or Wizard's PreRender.
So, to solve this issue, we need to have a judgement to see if the page has been posted back in these event handler.
I suggest you trying with the example below, which put your intializing code into If(!Page.IsPostBack) statement block.
Usfinecats
Member
10 Points
35 Posts
initializing an aspnet wizard
Jun 30, 2009 07:42 PM|LINK
I am looking for a place to initialize some variables in an aspnet Wizard.
I want this stuff to be called 1 time. After the constructor has been set up.
I've tried Wizard1_PreRender and Wizard1_Init, in both cases they are called with each Wizard step.
Where is the correct place for my initialization?
TIA
Usfinecats
pryanjr
Member
224 Points
101 Posts
Re: initializing an aspnet wizard
Jul 01, 2009 12:41 AM|LINK
What is being called? Try making a hander for the continue/next button etc.
RemithR
Contributor
2376 Points
396 Posts
Re: initializing an aspnet wizard
Jul 01, 2009 12:51 AM|LINK
Please try initializing in Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//initialize here
}
}
Shengqing Ya...
All-Star
45968 Points
2997 Posts
Re: initializing an aspnet wizard
Jul 01, 2009 06:30 AM|LINK
Hi,
You can locate the intializing code in either Wizard_PreRender and Wizard_Init event.
The key point in this case is page's postback. As we know, when next step is called in Wizard control, the page will postback and in this process, the page will load Wizard again, and call the event like Wizard's Init or Wizard's PreRender.
So, to solve this issue, we need to have a judgement to see if the page has been posted back in these event handler.
I suggest you trying with the example below, which put your intializing code into If(!Page.IsPostBack) statement block.
protected void Wizard1_PreRender(object sender, EventArgs e) { if (!Page.IsPostBack) { //your initializing code } }In addition, I would also like to suggest you having a read at this artilce talking about ASP.NET page life cycle: http://msdn.microsoft.com/en-us/library/ms178472.aspx.
And this one about Page.IsPostBack property: http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback.aspx.
I believe after reading these two articles, you can learn much related to this issue.
Best Regards,
Shengqing Yang
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework