Home All Groups Group Topic Archive Search About

asp.net 2.0 disabled=true problems

Author
10 Sep 2006 9:08 AM
moshi
Hey,
I'm working with asp.net 2.0.
I make objects (like ddl, textbox...) disabled=true in client side. Then,
when I get to the server in post action, these objects lose their value.
For example: ddl comes back after postback with the first values in it's
list - it doesn't keep the new value that the user chooses,
and textbox - still remains it's last value, like the user didn't alter it.
What I'm trying to say is that making object on client side disabled, harm
their value later on server side.
I thought maybe it is something in asp.net 2.0.
If someone knows something about it, I'll be glad to hear some advices.
Thanks a lot anyways!

Author
10 Sep 2006 6:27 PM
Otis Mukinfus
On Sun, 10 Sep 2006 02:08:01 -0700, moshi <mo***@discussions.microsoft.com>
wrote:

>Hey,
>I'm working with asp.net 2.0.
>I make objects (like ddl, textbox...) disabled=true in client side. Then,
>when I get to the server in post action, these objects lose their value.
>For example: ddl comes back after postback with the first values in it's
>list - it doesn't keep the new value that the user chooses,
>and textbox - still remains it's last value, like the user didn't alter it.
>What I'm trying to say is that making object on client side disabled, harm
>their value later on server side.
>I thought maybe it is something in asp.net 2.0.
>If someone knows something about it, I'll be glad to hear some advices.
>Thanks a lot anyways!

To make values survive postbacks you need to store them in ViewState Property of
the Page.

Example:

// before Postback:

int counter;
num = 1;
ViewState["num"] = 1;

// After the postback retrieve the value of counter:

if(ViewState["num"] != null)
{
    num = (int)ViewState["num"];
}
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Author
10 Sep 2006 6:57 PM
Otis Mukinfus
On Sun, 10 Sep 2006 13:27:14 -0500, Otis Mukinfus <ph***@emailaddress.com>
wrote:

Show quote
>On Sun, 10 Sep 2006 02:08:01 -0700, moshi <mo***@discussions.microsoft.com>
>wrote:
>
>>Hey,
>>I'm working with asp.net 2.0.
>>I make objects (like ddl, textbox...) disabled=true in client side. Then,
>>when I get to the server in post action, these objects lose their value.
>>For example: ddl comes back after postback with the first values in it's
>>list - it doesn't keep the new value that the user chooses,
>>and textbox - still remains it's last value, like the user didn't alter it.
>>What I'm trying to say is that making object on client side disabled, harm
>>their value later on server side.
>>I thought maybe it is something in asp.net 2.0.
>>If someone knows something about it, I'll be glad to hear some advices.
>>Thanks a lot anyways!
>
>To make values survive postbacks you need to store them in ViewState Property of
>the Page.
>
>Example:
>
>// before Postback:
>
>int counter;
>num = 1;
>ViewState["num"] = 1;
>
>// After the postback retrieve the value of counter:
>
>if(ViewState["num"] != null)
>{
>    num = (int)ViewState["num"];
>}
>Good luck with your project,
>
>Otis Mukinfus
>http://www.arltex.com
>http://www.tomchilders.com
OOPS!

That should be...

int num;
num = 1;
ViewState["num"] = 1;

// After the postback retrieve the value of counter:

if(ViewState["num"] != null)
{
    num = (int)ViewState["num"];
}

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Author
11 Sep 2006 5:15 AM
moshi
Hi there,
thanks for your assistance.
I think I wasn't clear - the problem I describe is that the user alters the
value of the ddl or text on client side, and then the field becomes disabled
and post to the server. in the server side it arrives with defect values -
the text box arrives with it's former value and the ddl with it's first value
in the list.
Hope that you'll have any idea,Thanks a lot.
btw - these filelds have enableviewstate=true

Show quote
"Otis Mukinfus" wrote:

> On Sun, 10 Sep 2006 13:27:14 -0500, Otis Mukinfus <ph***@emailaddress.com>
> wrote:
>
> >On Sun, 10 Sep 2006 02:08:01 -0700, moshi <mo***@discussions.microsoft.com>
> >wrote:
> >
> >>Hey,
> >>I'm working with asp.net 2.0.
> >>I make objects (like ddl, textbox...) disabled=true in client side. Then,
> >>when I get to the server in post action, these objects lose their value.
> >>For example: ddl comes back after postback with the first values in it's
> >>list - it doesn't keep the new value that the user chooses,
> >>and textbox - still remains it's last value, like the user didn't alter it.
> >>What I'm trying to say is that making object on client side disabled, harm
> >>their value later on server side.
> >>I thought maybe it is something in asp.net 2.0.
> >>If someone knows something about it, I'll be glad to hear some advices.
> >>Thanks a lot anyways!
> >
> >To make values survive postbacks you need to store them in ViewState Property of
> >the Page.
> >
> >Example:
> >
> >// before Postback:
> >
> >int counter;
> >num = 1;
> >ViewState["num"] = 1;
> >
> >// After the postback retrieve the value of counter:
> >
> >if(ViewState["num"] != null)
> >{
> >    num = (int)ViewState["num"];
> >}
> >Good luck with your project,
> >
> >Otis Mukinfus
> >http://www.arltex.com
> >http://www.tomchilders.com
> OOPS!
>
> That should be...
>
> int num;
> num = 1;
> ViewState["num"] = 1;
>
> // After the postback retrieve the value of counter:
>
> if(ViewState["num"] != null)
> {
>     num = (int)ViewState["num"];
> }
>
> Good luck with your project,
>
> Otis Mukinfus
> http://www.arltex.com
> http://www.tomchilders.com
>

AddThis Social Bookmark Button