asp.net 2.0 disabled=true problems

G

Guest

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!
 
O

Otis Mukinfus

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
 
O

Otis Mukinfus

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
 
G

Guest

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

Otis Mukinfus said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top