Accessing Composite Control Viewstate stored properties fromclientside Javascript


A

Andy

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?
 
Ad

Advertisements

A

Andy

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.
 
Ad

Advertisements

P

Patrice

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).
 

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

Top