viewstate on controls that are not enabled ?

Discussion in 'ASP .Net' started by Adrian Parker, May 3, 2005.

  1. 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
    Adrian Parker, May 3, 2005
    #1
    1. Advertising

  2. Adrian Parker

    Bruce Barker Guest

    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)



    "Adrian Parker" <> wrote in message
    news:%...
    > 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
    >
    >
    >
    Bruce Barker, May 3, 2005
    #2
    1. Advertising

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

    "Bruce Barker" <> wrote in message
    news:...
    > 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)
    >
    >
    >
    > "Adrian Parker" <> wrote in message
    > news:%...
    >> 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
    >>
    >>
    >>

    >
    >
    Adrian Parker, May 3, 2005
    #3
  4. 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.)
    Steven Cheng[MSFT], May 4, 2005
    #4
  5. Ok thanks guys, I'll give that a go.

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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.)
    >
    Adrian Parker, May 4, 2005
    #5
  6. 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.)
    Steven Cheng[MSFT], May 4, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabor
    Replies:
    3
    Views:
    616
    Jacob Yang [MSFT]
    Aug 26, 2003
  2. Cipher
    Replies:
    3
    Views:
    1,521
    coollzh
    Apr 30, 2004
  3. Leo J. Hart IV
    Replies:
    5
    Views:
    4,111
    Leo J. Hart IV
    Oct 10, 2004
  4. Keith Murray
    Replies:
    1
    Views:
    724
    Chris R. Timmons
    Oct 2, 2005
  5. nateastle
    Replies:
    1
    Views:
    1,445
    Jesse Houwing
    May 28, 2009
Loading...

Share This Page