468,507 Members | 1,642 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,507 developers. It's quick & easy.

Invalid ViewState

Nad
Hello,

I have a page with two link buttons. When I click on the first one I call
server.execute("target.aspx") to view target.aspx on the original page.
Then I click on the second link button and in this case I redirect to
another page, HOWEVER, I get Invalid ViewState exception. I know the problem
stems from server.execute but don't know why. Any Ideas?

Thank you.
Nov 19 '05 #1
11 2238
When you call Server.Execute, the second page is processed as part of the
first page. If the second page has any Controls in it, this will affect
(corrupt) the ViewState, as both pages have ViewState. I would recommend
using a UserControl instead of a second page instead. You can dynamically
load the UserControl if you need to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Hello,

I have a page with two link buttons. When I click on the first one I call
server.execute("target.aspx") to view target.aspx on the original page.
Then I click on the second link button and in this case I redirect to
another page, HOWEVER, I get Invalid ViewState exception. I know the
problem
stems from server.execute but don't know why. Any Ideas?

Thank you.

Nov 19 '05 #2
Nad
Thank you, I'll give it a try.

"Kevin Spencer" wrote:
When you call Server.Execute, the second page is processed as part of the
first page. If the second page has any Controls in it, this will affect
(corrupt) the ViewState, as both pages have ViewState. I would recommend
using a UserControl instead of a second page instead. You can dynamically
load the UserControl if you need to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Hello,

I have a page with two link buttons. When I click on the first one I call
server.execute("target.aspx") to view target.aspx on the original page.
Then I click on the second link button and in this case I redirect to
another page, HOWEVER, I get Invalid ViewState exception. I know the
problem
stems from server.execute but don't know why. Any Ideas?

Thank you.


Nov 19 '05 #3
Nad
Hi Kevin,

How do you load a usercontrol dynamically?

Why is that when on this page if I click on on a hyperlinkcolumn I don't get
that Invalid ViewState error but I do if I want to redirect by clicking on a
linkbutton?
"Kevin Spencer" wrote:
When you call Server.Execute, the second page is processed as part of the
first page. If the second page has any Controls in it, this will affect
(corrupt) the ViewState, as both pages have ViewState. I would recommend
using a UserControl instead of a second page instead. You can dynamically
load the UserControl if you need to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Hello,

I have a page with two link buttons. When I click on the first one I call
server.execute("target.aspx") to view target.aspx on the original page.
Then I click on the second link button and in this case I redirect to
another page, HOWEVER, I get Invalid ViewState exception. I know the
problem
stems from server.execute but don't know why. Any Ideas?

Thank you.


Nov 19 '05 #4
Nad
Hi Kevin,

How do you load a usercontrol dynamically?

Why is that when on this page if I click on on a hyperlinkcolumn I don't get
that Invalid ViewState error but I do if I want to redirect by clicking on a
linkbutton?
"Kevin Spencer" wrote:
When you call Server.Execute, the second page is processed as part of the
first page. If the second page has any Controls in it, this will affect
(corrupt) the ViewState, as both pages have ViewState. I would recommend
using a UserControl instead of a second page instead. You can dynamically
load the UserControl if you need to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
Hello,

I have a page with two link buttons. When I click on the first one I call
server.execute("target.aspx") to view target.aspx on the original page.
Then I click on the second link button and in this case I redirect to
another page, HOWEVER, I get Invalid ViewState exception. I know the
problem
stems from server.execute but don't know why. Any Ideas?

Thank you.


Nov 19 '05 #5
Hi Nad,
How do you load a usercontrol dynamically?
Use the Page.LoadControl() method. It takes a virtual path as its argument,
and returns a reference to the Control. Example:

MyControl = LoadControl("/DirName/AnotherDirName/ControlName.ascx")
Why is that when on this page if I click on on a hyperlinkcolumn I don't
get
that Invalid ViewState error but I do if I want to redirect by clicking on
a
linkbutton?
It's not what button you click. It's what function you call.
Response.Redirect redirects the client browser to request the second page.
Server.Execute adds the executed page's output to the current Page's
Response.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com... Hi Kevin,

How do you load a usercontrol dynamically?

Why is that when on this page if I click on on a hyperlinkcolumn I don't
get
that Invalid ViewState error but I do if I want to redirect by clicking on
a
linkbutton?
"Kevin Spencer" wrote:
When you call Server.Execute, the second page is processed as part of the
first page. If the second page has any Controls in it, this will affect
(corrupt) the ViewState, as both pages have ViewState. I would recommend
using a UserControl instead of a second page instead. You can dynamically
load the UserControl if you need to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
> Hello,
>
> I have a page with two link buttons. When I click on the first one I
> call
> server.execute("target.aspx") to view target.aspx on the original page.
> Then I click on the second link button and in this case I redirect to
> another page, HOWEVER, I get Invalid ViewState exception. I know the
> problem
> stems from server.execute but don't know why. Any Ideas?
>
> Thank you.


Nov 19 '05 #6
Nad
Hi Kevin,

Thank you for your reply. I think I didn't explain my second question well.

I have a datagrid row with 2 linkbutton columns and a hyperlinkbutton column.
If I click on the first linkbutton column which calls request.execute and
then I click on the second linkbutton I get invalid viewstate error. But if I
click on the hyperlinkbutton column it's ok and it takes me to the specified
web page.
Why is that?

"Kevin Spencer" wrote:
Hi Nad,
How do you load a usercontrol dynamically?


Use the Page.LoadControl() method. It takes a virtual path as its argument,
and returns a reference to the Control. Example:

MyControl = LoadControl("/DirName/AnotherDirName/ControlName.ascx")
Why is that when on this page if I click on on a hyperlinkcolumn I don't
get
that Invalid ViewState error but I do if I want to redirect by clicking on
a
linkbutton?


It's not what button you click. It's what function you call.
Response.Redirect redirects the client browser to request the second page.
Server.Execute adds the executed page's output to the current Page's
Response.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
Hi Kevin,

How do you load a usercontrol dynamically?

Why is that when on this page if I click on on a hyperlinkcolumn I don't
get
that Invalid ViewState error but I do if I want to redirect by clicking on
a
linkbutton?
"Kevin Spencer" wrote:
When you call Server.Execute, the second page is processed as part of the
first page. If the second page has any Controls in it, this will affect
(corrupt) the ViewState, as both pages have ViewState. I would recommend
using a UserControl instead of a second page instead. You can dynamically
load the UserControl if you need to.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com...
> Hello,
>
> I have a page with two link buttons. When I click on the first one I
> call
> server.execute("target.aspx") to view target.aspx on the original page.
> Then I click on the second link button and in this case I redirect to
> another page, HOWEVER, I get Invalid ViewState exception. I know the
> problem
> stems from server.execute but don't know why. Any Ideas?
>
> Thank you.


Nov 19 '05 #7
I understood the question. Here's your original message (the salient part):
> I have a page with two link buttons. When I click on the first one I
> call
> server.execute("target.aspx") to view target.aspx on the original
> page.
> Then I click on the second link button and in this case I redirect to
> another page, HOWEVER, I get Invalid ViewState exception. I know the
> problem
> stems from server.execute but don't know why. Any Ideas?

Note that only one of the buttons you mentioned calls Server.Execute. The
other calls Response.Redirect. At least according to what you said.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com... Hi Kevin,

Thank you for your reply. I think I didn't explain my second question
well.

I have a datagrid row with 2 linkbutton columns and a hyperlinkbutton
column.
If I click on the first linkbutton column which calls request.execute and
then I click on the second linkbutton I get invalid viewstate error. But
if I
click on the hyperlinkbutton column it's ok and it takes me to the
specified
web page.
Why is that?

"Kevin Spencer" wrote:
Hi Nad,
> How do you load a usercontrol dynamically?


Use the Page.LoadControl() method. It takes a virtual path as its
argument,
and returns a reference to the Control. Example:

MyControl = LoadControl("/DirName/AnotherDirName/ControlName.ascx")
> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?


It's not what button you click. It's what function you call.
Response.Redirect redirects the client browser to request the second
page.
Server.Execute adds the executed page's output to the current Page's
Response.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
> Hi Kevin,
>
> How do you load a usercontrol dynamically?
>
> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?
>
>
> "Kevin Spencer" wrote:
>
>> When you call Server.Execute, the second page is processed as part of
>> the
>> first page. If the second page has any Controls in it, this will
>> affect
>> (corrupt) the ViewState, as both pages have ViewState. I would
>> recommend
>> using a UserControl instead of a second page instead. You can
>> dynamically
>> load the UserControl if you need to.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> Ambiguity has a certain quality to it.
>>
>> "Nad" <Na*@discussions.microsoft.com> wrote in message
>> news:1B**********************************@microsof t.com...
>> > Hello,
>> >
>> > I have a page with two link buttons. When I click on the first one I
>> > call
>> > server.execute("target.aspx") to view target.aspx on the original
>> > page.
>> > Then I click on the second link button and in this case I redirect
>> > to
>> > another page, HOWEVER, I get Invalid ViewState exception. I know the
>> > problem
>> > stems from server.execute but don't know why. Any Ideas?
>> >
>> > Thank you.
>>
>>
>>


Nov 19 '05 #8
Maybe I'm not understanding you very well. It occurs to me that you may be
saying that if you don't click on the button that calls Server.Execute, and
then click on the hyperlink button, you don't get the Invalid ViewState
error, but if you do click on the first button (which calls Server.Execute)
and THAN click on the same page with the hyperlink button, you DO get the
error. Is that correct? If so, the answwer is still the same. Let me
explain. when you call Server.Execute, you don't get the Invalid ViewState
until you do another PostBack. Why? Because the ViewState is evaluated after
a PostBack, which doesn't occur until you click some element that causes a
PostBack. IOW, when you click the first button, it causes a PostBack. The
ViewState is fine, and it passes the test. Then the app adds the second page
to the first, and returns it to the browser. Now, on the browser side
everything is fine (sort of: at least the browser can parse the document).
But when you do a PostBack, you have a corrupt ViewState which was produced
by your last PostBack followed by Server.Execute.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
Hi Kevin,

Thank you for your reply. I think I didn't explain my second question
well.

I have a datagrid row with 2 linkbutton columns and a hyperlinkbutton
column.
If I click on the first linkbutton column which calls request.execute and
then I click on the second linkbutton I get invalid viewstate error. But
if I
click on the hyperlinkbutton column it's ok and it takes me to the
specified
web page.
Why is that?

"Kevin Spencer" wrote:
Hi Nad,
> How do you load a usercontrol dynamically?


Use the Page.LoadControl() method. It takes a virtual path as its
argument,
and returns a reference to the Control. Example:

MyControl = LoadControl("/DirName/AnotherDirName/ControlName.ascx")
> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?


It's not what button you click. It's what function you call.
Response.Redirect redirects the client browser to request the second
page.
Server.Execute adds the executed page's output to the current Page's
Response.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
> Hi Kevin,
>
> How do you load a usercontrol dynamically?
>
> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?
>
>
> "Kevin Spencer" wrote:
>
>> When you call Server.Execute, the second page is processed as part of
>> the
>> first page. If the second page has any Controls in it, this will
>> affect
>> (corrupt) the ViewState, as both pages have ViewState. I would
>> recommend
>> using a UserControl instead of a second page instead. You can
>> dynamically
>> load the UserControl if you need to.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> Ambiguity has a certain quality to it.
>>
>> "Nad" <Na*@discussions.microsoft.com> wrote in message
>> news:1B**********************************@microsof t.com...
>> > Hello,
>> >
>> > I have a page with two link buttons. When I click on the first one I
>> > call
>> > server.execute("target.aspx") to view target.aspx on the original
>> > page.
>> > Then I click on the second link button and in this case I redirect
>> > to
>> > another page, HOWEVER, I get Invalid ViewState exception. I know the
>> > problem
>> > stems from server.execute but don't know why. Any Ideas?
>> >
>> > Thank you.
>>
>>
>>


Nov 19 '05 #9
Nad
Kevin,

Thank you for the time you took to reply.

You misunderstood.

Here are two scenarios that I perform SEPERATELY.

Scenario 1.
a. I open the page and click on the first linkbutton (with call to
server.execute)
b. I click on the 2nd linkbutton which redirects to another page
result: Invalid ViewState

Scenario 2.
a. I open the page and click on the first linkbutton (with call to
server.execute)
b. I click on the hyperlinkbutton (which redirects to another page)
result: the page opens and there are no errors

Why are the results inconsistent?

"Kevin Spencer" wrote:
Maybe I'm not understanding you very well. It occurs to me that you may be
saying that if you don't click on the button that calls Server.Execute, and
then click on the hyperlink button, you don't get the Invalid ViewState
error, but if you do click on the first button (which calls Server.Execute)
and THAN click on the same page with the hyperlink button, you DO get the
error. Is that correct? If so, the answwer is still the same. Let me
explain. when you call Server.Execute, you don't get the Invalid ViewState
until you do another PostBack. Why? Because the ViewState is evaluated after
a PostBack, which doesn't occur until you click some element that causes a
PostBack. IOW, when you click the first button, it causes a PostBack. The
ViewState is fine, and it passes the test. Then the app adds the second page
to the first, and returns it to the browser. Now, on the browser side
everything is fine (sort of: at least the browser can parse the document).
But when you do a PostBack, you have a corrupt ViewState which was produced
by your last PostBack followed by Server.Execute.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
Hi Kevin,

Thank you for your reply. I think I didn't explain my second question
well.

I have a datagrid row with 2 linkbutton columns and a hyperlinkbutton
column.
If I click on the first linkbutton column which calls request.execute and
then I click on the second linkbutton I get invalid viewstate error. But
if I
click on the hyperlinkbutton column it's ok and it takes me to the
specified
web page.
Why is that?

"Kevin Spencer" wrote:
Hi Nad,

> How do you load a usercontrol dynamically?

Use the Page.LoadControl() method. It takes a virtual path as its
argument,
and returns a reference to the Control. Example:

MyControl = LoadControl("/DirName/AnotherDirName/ControlName.ascx")

> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?

It's not what button you click. It's what function you call.
Response.Redirect redirects the client browser to request the second
page.
Server.Execute adds the executed page's output to the current Page's
Response.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
> Hi Kevin,
>
> How do you load a usercontrol dynamically?
>
> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?
>
>
> "Kevin Spencer" wrote:
>
>> When you call Server.Execute, the second page is processed as part of
>> the
>> first page. If the second page has any Controls in it, this will
>> affect
>> (corrupt) the ViewState, as both pages have ViewState. I would
>> recommend
>> using a UserControl instead of a second page instead. You can
>> dynamically
>> load the UserControl if you need to.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> Ambiguity has a certain quality to it.
>>
>> "Nad" <Na*@discussions.microsoft.com> wrote in message
>> news:1B**********************************@microsof t.com...
>> > Hello,
>> >
>> > I have a page with two link buttons. When I click on the first one I
>> > call
>> > server.execute("target.aspx") to view target.aspx on the original
>> > page.
>> > Then I click on the second link button and in this case I redirect
>> > to
>> > another page, HOWEVER, I get Invalid ViewState exception. I know the
>> > problem
>> > stems from server.execute but don't know why. Any Ideas?
>> >
>> > Thank you.
>>
>>
>>


Nov 19 '05 #10
Nad
Sorry to bother you Kevin but I am not able to fix the invalid viewstate by
loading a usercontrol dynamically, here's what I'm doing:

1. In the page_load of the usercontrol I write:
StringWriter swrTarget = new StringWriter();
Server.Execute("myPage.aspx", swrTarget);
myLiteral.Text = swrTarget.ToString();

2. AND in the ItemCommand of the original page's datagrid control I write:

myUserControl userControl = (myUserControl) LoadControl("myUserControl.ascx");
myPanel.Controls.Add(userControl);

BUT I still get the same error.
"Kevin Spencer" wrote:
Maybe I'm not understanding you very well. It occurs to me that you may be
saying that if you don't click on the button that calls Server.Execute, and
then click on the hyperlink button, you don't get the Invalid ViewState
error, but if you do click on the first button (which calls Server.Execute)
and THAN click on the same page with the hyperlink button, you DO get the
error. Is that correct? If so, the answwer is still the same. Let me
explain. when you call Server.Execute, you don't get the Invalid ViewState
until you do another PostBack. Why? Because the ViewState is evaluated after
a PostBack, which doesn't occur until you click some element that causes a
PostBack. IOW, when you click the first button, it causes a PostBack. The
ViewState is fine, and it passes the test. Then the app adds the second page
to the first, and returns it to the browser. Now, on the browser side
everything is fine (sort of: at least the browser can parse the document).
But when you do a PostBack, you have a corrupt ViewState which was produced
by your last PostBack followed by Server.Execute.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
Hi Kevin,

Thank you for your reply. I think I didn't explain my second question
well.

I have a datagrid row with 2 linkbutton columns and a hyperlinkbutton
column.
If I click on the first linkbutton column which calls request.execute and
then I click on the second linkbutton I get invalid viewstate error. But
if I
click on the hyperlinkbutton column it's ok and it takes me to the
specified
web page.
Why is that?

"Kevin Spencer" wrote:
Hi Nad,

> How do you load a usercontrol dynamically?

Use the Page.LoadControl() method. It takes a virtual path as its
argument,
and returns a reference to the Control. Example:

MyControl = LoadControl("/DirName/AnotherDirName/ControlName.ascx")

> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?

It's not what button you click. It's what function you call.
Response.Redirect redirects the client browser to request the second
page.
Server.Execute adds the executed page's output to the current Page's
Response.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
> Hi Kevin,
>
> How do you load a usercontrol dynamically?
>
> Why is that when on this page if I click on on a hyperlinkcolumn I
> don't
> get
> that Invalid ViewState error but I do if I want to redirect by clicking
> on
> a
> linkbutton?
>
>
> "Kevin Spencer" wrote:
>
>> When you call Server.Execute, the second page is processed as part of
>> the
>> first page. If the second page has any Controls in it, this will
>> affect
>> (corrupt) the ViewState, as both pages have ViewState. I would
>> recommend
>> using a UserControl instead of a second page instead. You can
>> dynamically
>> load the UserControl if you need to.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> Ambiguity has a certain quality to it.
>>
>> "Nad" <Na*@discussions.microsoft.com> wrote in message
>> news:1B**********************************@microsof t.com...
>> > Hello,
>> >
>> > I have a page with two link buttons. When I click on the first one I
>> > call
>> > server.execute("target.aspx") to view target.aspx on the original
>> > page.
>> > Then I click on the second link button and in this case I redirect
>> > to
>> > another page, HOWEVER, I get Invalid ViewState exception. I know the
>> > problem
>> > stems from server.execute but don't know why. Any Ideas?
>> >
>> > Thank you.
>>
>>
>>


Nov 19 '05 #11
If you get rid of ALL Server.Execute code, and replace it with
dynamically-loaded UserControls, I'm willing to bet dollars to doughnuts
that your problems will go away.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Sorry to bother you Kevin but I am not able to fix the invalid viewstate
by
loading a usercontrol dynamically, here's what I'm doing:

1. In the page_load of the usercontrol I write:
StringWriter swrTarget = new StringWriter();
Server.Execute("myPage.aspx", swrTarget);
myLiteral.Text = swrTarget.ToString();

2. AND in the ItemCommand of the original page's datagrid control I write:

myUserControl userControl = (myUserControl)
LoadControl("myUserControl.ascx");
myPanel.Controls.Add(userControl);

BUT I still get the same error.
"Kevin Spencer" wrote:
Maybe I'm not understanding you very well. It occurs to me that you may
be
saying that if you don't click on the button that calls Server.Execute,
and
then click on the hyperlink button, you don't get the Invalid ViewState
error, but if you do click on the first button (which calls
Server.Execute)
and THAN click on the same page with the hyperlink button, you DO get the
error. Is that correct? If so, the answwer is still the same. Let me
explain. when you call Server.Execute, you don't get the Invalid
ViewState
until you do another PostBack. Why? Because the ViewState is evaluated
after
a PostBack, which doesn't occur until you click some element that causes
a
PostBack. IOW, when you click the first button, it causes a PostBack. The
ViewState is fine, and it passes the test. Then the app adds the second
page
to the first, and returns it to the browser. Now, on the browser side
everything is fine (sort of: at least the browser can parse the
document).
But when you do a PostBack, you have a corrupt ViewState which was
produced
by your last PostBack followed by Server.Execute.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
> Hi Kevin,
>
> Thank you for your reply. I think I didn't explain my second question
> well.
>
> I have a datagrid row with 2 linkbutton columns and a hyperlinkbutton
> column.
> If I click on the first linkbutton column which calls request.execute
> and
> then I click on the second linkbutton I get invalid viewstate error.
> But
> if I
> click on the hyperlinkbutton column it's ok and it takes me to the
> specified
> web page.
> Why is that?
>
> "Kevin Spencer" wrote:
>
>> Hi Nad,
>>
>> > How do you load a usercontrol dynamically?
>>
>> Use the Page.LoadControl() method. It takes a virtual path as its
>> argument,
>> and returns a reference to the Control. Example:
>>
>> MyControl = LoadControl("/DirName/AnotherDirName/ControlName.ascx")
>>
>> > Why is that when on this page if I click on on a hyperlinkcolumn I
>> > don't
>> > get
>> > that Invalid ViewState error but I do if I want to redirect by
>> > clicking
>> > on
>> > a
>> > linkbutton?
>>
>> It's not what button you click. It's what function you call.
>> Response.Redirect redirects the client browser to request the second
>> page.
>> Server.Execute adds the executed page's output to the current Page's
>> Response.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> Ambiguity has a certain quality to it.
>>
>> "Nad" <Na*@discussions.microsoft.com> wrote in message
>> news:91**********************************@microsof t.com...
>> > Hi Kevin,
>> >
>> > How do you load a usercontrol dynamically?
>> >
>> > Why is that when on this page if I click on on a hyperlinkcolumn I
>> > don't
>> > get
>> > that Invalid ViewState error but I do if I want to redirect by
>> > clicking
>> > on
>> > a
>> > linkbutton?
>> >
>> >
>> > "Kevin Spencer" wrote:
>> >
>> >> When you call Server.Execute, the second page is processed as part
>> >> of
>> >> the
>> >> first page. If the second page has any Controls in it, this will
>> >> affect
>> >> (corrupt) the ViewState, as both pages have ViewState. I would
>> >> recommend
>> >> using a UserControl instead of a second page instead. You can
>> >> dynamically
>> >> load the UserControl if you need to.
>> >>
>> >> --
>> >> HTH,
>> >>
>> >> Kevin Spencer
>> >> Microsoft MVP
>> >> ..Net Developer
>> >> Ambiguity has a certain quality to it.
>> >>
>> >> "Nad" <Na*@discussions.microsoft.com> wrote in message
>> >> news:1B**********************************@microsof t.com...
>> >> > Hello,
>> >> >
>> >> > I have a page with two link buttons. When I click on the first
>> >> > one I
>> >> > call
>> >> > server.execute("target.aspx") to view target.aspx on the original
>> >> > page.
>> >> > Then I click on the second link button and in this case I
>> >> > redirect
>> >> > to
>> >> > another page, HOWEVER, I get Invalid ViewState exception. I know
>> >> > the
>> >> > problem
>> >> > stems from server.execute but don't know why. Any Ideas?
>> >> >
>> >> > Thank you.
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Anup Jishnu | last post: by
5 posts views Thread by Anup Jishnu | last post: by
6 posts views Thread by vinay | last post: by
reply views Thread by tynorton | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.