viewstate on controls that are not enabled ?

A

Adrian Parker

Trying to write a page with several controls on it, some of which, depending
on the process login, are enabled and some disabled. When I click on a save
button to cause a postback event to fire, the controls that are not enabled
don't have their data returned, so in the UpdateClick event, the controls
contain nothing.

How do I get it to maintain the state even for these columns ?

thanks
Adrian
 
B

Bruce Barker

the browser does not postback values for disabled fields. you will need
client script to copy the values to a hidden field. if you disable them in
the code behind, save their disabled value in viewstate, then restore it on
postback.

-- bruce (sqlwork.com)
 
A

Adrian Parker

Is there any easier way of not allowing entry of fields apart from setting
enabled to false ?
 
S

Steven Cheng[MSFT]

Hi Adrian,

I think Bruce's suggestions are reasonable since disabled html input fields
won't post back their values. And there hasn't any better means other than
copy and store the values into other place(viewstate or sessionstaet)
before disabling the entry fields.

BTW, is it possbile that we don't disable them? For some control such as
TextBox( <input type=text ... ), we can set it's "readonly" attribute. For
example:

txtName.Attributes["readonly"] = "true";

the above statement make the txtName (a textbox control) readonly( can't
change its text), but its value can still be posted back to server side.
In addition, we can also consider settting those control's Visible to false
so as to hidden them.

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

OK. If there are any further questions or anything else we can help, please
always feel free to post here.

Good Luck! :)

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top