开发者

"Page.IsValid cannot be called" occurs in Page_PreRender event handler

开发者 https://www.devze.com 2023-01-17 08:23 出处:网络
I\'m currently learning ASP.NET, and read that the page validation occurs after Page.Load(). When I put

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();
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消