Accessing Composite Control Viewstate stored properties fromclientside Javascript

Discussion in 'ASP .Net' started by Andy, Apr 8, 2010.

  1. Andy

    Andy Guest

    I've created a composite control called GRIDLOOKUP that contains an
    ASP:LINKBUTTON and ASP:IMAGEBUTTON. I've also added TEXT and KEY
    properties to GRIDLOOKUP which store their values in GRIDLOOKUP's
    viewstate.

    GRIDLOOKUP copies its TEXT property to the LINKBUTTON's TEXT property,
    so that the current value of GRIDLOOKUP is displayed in the
    LINKBUTTON. When GRIDLOOKUP makes its round trip between the client
    and server, both TEXT and KEY properties are persisted properly.

    I've placed GRIDLOOKUP in a DataGrid Template on a webpage. When the
    webpage runs, the datagrid renders GRIDLOOKUP correctly, and the
    values for the column GRIDLOOKUP is attached to appear correctly in
    the LINKBUTTON.

    When the user clicks the IMAGEBUTTON, I want to change the values of
    TEXT and KEY for the corresponding GRIDLOOKUP the user selected
    through javascript on the clientside.. Unfortunately, GRIDLOOKUP
    renders only the LINKBUTTON and IMAGEBUTTON. There is no GRIDLOOKUP
    control visible in the HTML of the page. Yet, in the codebehind of
    the webpage during the postback, I can access the TEXT and KEY
    properties of GRIDLOOKUP.

    Should I be accessing TEXT from the LINKBUTTON instead during the
    postback to the webpage and transfering its value to the GRIDLOOKUP
    composite control at that point?

    Or is there a way to do this from the GRIDLOOKUP codebehind?
    Andy, Apr 8, 2010
    #1
    1. Advertising

  2. Andy

    Andy Guest

    After running a viewstate parser, changing the values of various
    controls on a webpage, and inspecting the viewstate on both the client
    and the server, I've determined that viewstate is never manipulated,
    saved, or accessed on the client from clientside script code, internet
    explorer, or anything else in a client tier.

    Viewstate is solely a mechanisim for persisting property values set in
    server-side codebehinds between consecutive invocations of that
    codebehind. It does not transfer any new values keyed by a user on a
    client to the server-side codebehind. It only provides functionality
    that is similar to what asp.session variables or page.caches provide
    to persist data in server-side code, except that the client is used to
    store the persisted data rather than any server resources.

    The only way to persist values keyed by a user in a clientside control
    via viewstate is to have the control do a postback to the codebehind
    where its value is then read from the Request.Form NameValueCollection
    and manually copied to a viewstate variable. The contents of that
    variable will then be available again in subsequent invocations of the
    codebehind only.

    ASP.NET has another mechanism to automatically pre-populate
    ASP:Controls from a previous post, however, it does this from the
    form's posted data rather than from viewstate.
    Andy, Apr 9, 2010
    #2
    1. Advertising

  3. Andy

    Patrice Guest

    Re: Accessing Composite Control Viewstate stored properties from clientside Javascript

    > Unfortunately, GRIDLOOKUP
    > renders only the LINKBUTTON and IMAGEBUTTON. There is no GRIDLOOKUP
    > control visible in the HTML of the page.


    Ultimately ASP.NET renders an HTML page.

    > Yet, in the codebehind of
    > the webpage during the postback, I can access the TEXT and KEY
    > properties of GRIDLOOKUP.


    The controls you are suign server side are just a programming model that
    allows to easily generate HTML markup code consumed by browser so this
    programming model is only available server side.

    > Should I be accessing TEXT from the LINKBUTTON instead during the
    > postback to the webpage and transfering its value to the GRIDLOOKUP
    > composite control at that point?


    Not sure to really understand what you are trying to do but :
    - you'll know which control triggered the postback. As text and value are
    persisted in view state you'll be able then to know which values are
    associated with the clicked control.

    If you want to get this client side rather than server side, this is done by
    generating the appropriate client side code that will use the current value
    of text and key to create the event handler (the viewstate is just an
    internal "value bag" that you'll never access client side this way, you have
    to explictely inject client side the data you need).

    --
    Patrice
    Patrice, Apr 9, 2010
    #3
    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. sleigh
    Replies:
    1
    Views:
    2,674
    sleigh
    Feb 12, 2004
  2. Matt T.

    Composite Control - Viewstate management for complex properties

    Matt T., Sep 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    205
    Teemu Keiski
    Sep 11, 2004
  3. Chad
    Replies:
    0
    Views:
    211
  4. Paul Yanzick
    Replies:
    4
    Views:
    490
    Steven Cheng[MSFT]
    Jan 9, 2006
  5. whoisnidhee

    ViewState of the Composite Control composed of custom control

    whoisnidhee, Jul 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    312
    Nidhee
    Jul 16, 2004
Loading...

Share This Page