Postback confusion

  • Thread starter Thread starter Keithb
  • Start date Start date
K

Keithb

A page's Page_Load event contains initialization code (shown below),
intended to execute only once when the page is loaded for the first time.
After page load, the first time the user clicks an Update button, the
initialization code is executed a second time, cancelling out the users
check box entries. Subsequent clicks to the Update button do not execute the
initialization code and everything works properly. What can I do so that
this page initializes only once?

Thanks,

Keith

if (!Page.IsPostBack)
{
EndPointCB.Checked = false;
BusSvcCB.Checked = false;
AppSvcCB.Checked = false;
SampleXmlCB.Checked = false;
if (BindSelectSvcGroupDDL())
{
if (BindSelectSvcVerDDL())
{
String svcGroup = SelectSvcGroupDDL.SelectedItem.Text;
String svcName = FindSvcTB.Text;
String svcVer = SelectSvcVerDDL.SelectedItem.Text;
bool ShowEndPoint = EndPointCB.Checked;
bool ShowBusSvc = BusSvcCB.Checked;
bool ShowAppSvc = AppSvcCB.Checked;
bool ShowSampleXML = SampleXmlCB.Checked;
String UserRole = "None";
BindGrid(svcGroup, svcName, svcVer, UserRole,
ShowEndPoint, ShowBusSvc, ShowAppSvc, ShowSampleXML);

}
}
}
 
Hi Keith,

The problem might actually be in your Update button click event.
The code you posted looks fine to me, and should not be executing after
the Update button is clicked.

However, if your Update button is doing a Redirect or Transfer to the
same page (which is not uncommon) then this will act as a normal page
request from scratch, thus postback will equal false.

Hope this helps,
Steven
 
Back
Top