472,800 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,800 software developers and data experts.

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 2408
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Anup Jishnu | last post by:
Hi, I have installed ASP.Net application on a system. When accessing the Application from within the LAN, it works fine. However, when I access the application from the Internet, some pages...
4
by: Ersin Gençtürk | last post by:
Server : WEB System.Web.HttpUnhandledException: Exception of type System.Web.HttpUnhandledException was thrown. ---> System.Web.HttpException: The View State is invalid for this page and might be...
2
by: Mike | last post by:
hi to all does any body know or receive this message before and how i can repare this: The viewstate is invalid for this page and might be corrupted. thank's Mike
2
by: Brad | last post by:
I have an intranet app that has just started sporadically getting the following error "The viewstate is invalid for this page and might be corrupted." By sproadic I mean 3-4 times during the past...
5
by: Anup Jishnu | last post by:
Hi, I have installed ASP.Net application on a system. When accessing the Application from within the LAN, it works fine. However, when I access the application from the Internet, some pages...
7
by: Jason | last post by:
Can anybody help on the following error : The viewstate is invalid for this page and might be corrupted. Description: An unhandled exception occurred during the execution of the current web...
6
by: vinay | last post by:
What is this error?? Exception Details: System.Web.HttpException: Unable to validate data. System.Web.Configuration.MachineKey.GetDecodedData(Byte buf, Byte modifier, Int32 start, Int32...
9
by: Jamie | last post by:
I am receiving an Invalid ViewState error after posting back to the same page twice. Consistently the error occurs after the second postback and not after the first. I have looked into creating...
0
by: tynorton | last post by:
Hey, I've been working on this issue for a while now, with no leads or success. The scenario is a homemade modal dialog using UpdatePanels. There a couple ImageButtons inside of usercontrols...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.