Reputation: 1745
I have the next code.
protected void Page_PreRender(object sender, EventArgs e)
{
bool isDelayWarning = proxy.MerchantPaySystemSetting_IsHoldPaymentsAllow(clientID, PaySystem.Type));
ViewState.Add("IsDelayWarning", isDelayWarning);
}
protected void btnSend_Click(object sender, EventArgs e)
{
if ((bool)ViewState["IsDelayWarning"] && !cbxDelayConfirm.Checked)
{
this.CustomErrorMessage = Yandex_Term_Error;
return;
}
}
In btnSend_Click method ViewState["IsDelayWarning"] = null.
How can I resolve this trouble?
Thanks! :)
Upvotes: 0
Views: 273
Reputation: 31
You can always check for null reference by doing something like this
if (something != null)
code ------
or another way if you will sometimes have null is to use. For example if user address is null
if (thisuser.Address == null)
{
thisuser.Address = new Address();
}
thisuser.Address = user.Address.City;
Upvotes: 0
Reputation: 67382
I'm not sure about the logic you're going for, but a button push happens during post-back, before the page is rendered. Put breakpoints in your two methods to see their relative order.
Pay attention to the yellow marked items, control event processing is one of them and it happens strictly before PreRender
.
Upvotes: 1