Whoa! Big title there. This article applies to errors in ASP.NET 2.0 when trying to dynamically render a gridview with paging.

I have been trying to "Ajaxify" my web programming and I've found that the easiest method is to wrap everything I need in Web User Controls, render the controls, then send the rendered string through ajax to fill some innerHTML.
Well, the fine people at Microsoft thought otherwise. I have been trying to render a web user control with a gridview inside it for 3 hours now and nothing helped. I kept getting a NullReferenceException when calling GridView.DataBind and the StackTrace showed it originated in the BuildCallBackArgument(int) method.
Nothing helped except actually decompiling the code of the GridView itself. I've found out that it called a method in the Page of the control, in other words it needed a page. I gave it a page, but then another problem occured that I'd already solved here. I already had a parent page that overrode the offending method, so the final code is this:
ParentPage pp=new ParentPage();  // where ParentPage is a Page with VerifyRenderingInServerForm(Control control) overriden so it doesn't do anything
pp.EnableEventValidation = false; //another silly error
uc.Page = pp; //uc is the user control needing rendering
uc.Bind();

Comments

naga

<p>hey thanks for your fast response. I tried that too but its not working. still its showing the current page data only. suggest some other way.</p>

naga

Siderite

<p>Just set AllowPaging to false when you render it to export.</p>

Siderite

naga

<p>thank u. I have one problem in exporting the gridview to an excel sheet. in the grid im using the paging but in the excel sheet i want all the rows to be displayed.</p>

naga

naga

hey thanks for your fast response. I tried that too but its not working. still its showing the current page data only. suggest some other way.

naga

Siderite

Just set AllowPaging to false when you render it to export.

Siderite

naga

thank u. I have one problem in exporting the gridview to an excel sheet. in the grid im using the paging but in the excel sheet i want all the rows to be displayed.

naga

Siderite

<p>It's really simple. You create a new class called ParentPage, inheriting from System.Web.UI.Page.In it you override VerifyRenderingInServerForm and in it you do nothing, not even call the base.VerifyRenderingInServerForm method.<br><br>Then you use an instance of the ParentPage class as the Page property of the grid you want to render.</p>

Siderite

naga

<p>hi, I too have the same problem can u pls explain your code. what is the parent page in your code?</p>

naga

Siderite

It&#39;s really simple. You create a new class called ParentPage, inheriting from System.Web.UI.Page.In it you override VerifyRenderingInServerForm and in it you do nothing, not even call the base.VerifyRenderingInServerForm method.<br><br>Then you use an instance of the ParentPage class as the Page property of the grid you want to render.

Siderite

naga

hi, I too have the same problem can u pls explain your code. what is the parent page in your code?

naga

Anonymous

<p>Really thank you for this code ! <br><br>I managed to get it working after 3 long hours of search.</p>

Anonymous

Anonymous

Really thank you for this code ! <br><br>I managed to get it working after 3 long hours of search.

Anonymous

Siderite

<p>Oops, sorry. I often copy paste then addapt the code directly in the blog.<br> I've fixed the entry, 'bs' was 'pp' and added an explanation for ParentPage. It's a custom object inherited from Page which overrides VerifyRenderingInServerForm(Control control) with a method with an empty body.</p>

Siderite

Siderite

Oops, sorry. I often copy paste then addapt the code directly in the blog.<br> I&#39;ve fixed the entry, &#39;bs&#39; was &#39;pp&#39; and added an explanation for ParentPage. It&#39;s a custom object inherited from Page which overrides VerifyRenderingInServerForm(Control control) with a method with an empty body.

Siderite

Mike

<p>I have this exact same frustrating problem, but I don't understand your solution.<br><br>1) What is the ParentPage? I don't see that type available.<br><br>2) What is "bs" in your code example?</p>

Mike

Mike

I have this exact same frustrating problem, but I don&#39;t understand your solution.<br><br>1) What is the ParentPage? I don&#39;t see that type available.<br><br>2) What is &quot;bs&quot; in your code example?

Mike

Manik

<p>Hey Man!! thanks a lot !!<br> I had this problem too .. got it working just fine!! <br> Don't know Why Microsoft people couldn't mention this in their documentation .. do they expect everyone to read their code .. esp. wen they won't even let it out..</p>

Manik

Manik

Hey Man!! thanks a lot !!<br> I had this problem too .. got it working just fine!! <br> Don&#39;t know Why Microsoft people couldn&#39;t mention this in their documentation .. do they expect everyone to read their code .. esp. wen they won&#39;t even let it out..

Manik

Post a comment