"Page.IsValid cannot be called" occurs in Page_PreRender event handler
I'm currently learning ASP.NET, and read that the page validation occurs after Page.Load(). When I put if (Page.IsValid == true) whatever;
then I get an error, even though that line is in my Page_PreRender() event handler.
How does that make sense?
Thanks in advance, just trying to under开发者_如何学JAVAstand it fully.
You either have to have a control that causes validation doing the postback (CausesValidation="true"
) or actually call Page.Validate()
manually for Page.IsValid
to be accessible...otherwise validation hasn't happened, so there's just nothing to check, the value would be meaningless, which is the current error you're seeing.
The solution does work, I was having problem in OnPageIndexChanging event I used below code
protected void gvRequests_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
Page.Validate();
gvMyRequest.PageIndex = e.NewPageIndex;
Populate();
}
精彩评论