the cause is always the same in .Net: You are trying to use a reference variable who’s value is Nothing/null.
When the value is Nothing/null for the reference variable, that means it is not actually holding a reference to an instance of any object that exists on the heap.
Your following code has something wrong, you can set the breakpoint to debug it.
MainPanel.CssClass = "Value" ***
Please mark the replies as answers if they help or unmark if not.
OnPreRender event, your page is still renderding so it's possible that your MainPanel isn't there yet. Not sure whether this will work because I don't have much idea about what's the base class OnPreRender methods looks like. But try by changing the
places of the lines
mohdalbakri
0 Points
1 Post
ASP Controls gives object Reference exception when Page.Redirect
Mar 06, 2012 07:23 PM|LINK
Hello all ,
I have two pages
Page 1 :-
User Control with link button onClick
Response.Redirect(“Page2.aspx”);
Page 2 :-
Have OnPreRender event , calling method A()
protected override void OnPreRender(EventArgs e)
{
MethodA();
base.OnPreRender(e);
}
public void MethodA()
{
MainPanel.CssClass = "Value" ***
}
i got an exception(Object reference not set ,,,) from line with *** ,,,
on debug mode , i checked all controls in page its give null values
i changed the Page.Redirect to Server.Transfer() but i am get same thing...
any ideas?????
Hua-Jun Li -...
All-Star
75950 Points
5608 Posts
Re: ASP Controls gives object Reference exception when Page.Redirect
Mar 08, 2012 07:16 AM|LINK
Hi,
the cause is always the same in .Net: You are trying to use a reference variable who’s value is Nothing/null.
When the value is Nothing/null for the reference variable, that means it is not actually holding a reference to an instance of any object that exists on the heap.
Your following code has something wrong, you can set the breakpoint to debug it.
MainPanel.CssClass = "Value" ***
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
Ruchira
All-Star
43054 Points
7039 Posts
MVP
Re: ASP Controls gives object Reference exception when Page.Redirect
Mar 08, 2012 07:31 AM|LINK
OnPreRender event, your page is still renderding so it's possible that your MainPanel isn't there yet. Not sure whether this will work because I don't have much idea about what's the base class OnPreRender methods looks like. But try by changing the places of the lines
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); MethodA(); }Please correct me if I'm wrong. Honestly, I don't have much idea about this.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.