Retrieving a HTML Element's Value via Request.Params

P

Praveen

As you all know the value of input, checkbox and other "user editable"
elements can be retrieved on postback via Request.Params list, if you
know their ID.

However, if there is a span element (for example) whose value gets
updated via javascript when the user does something, that value is not
made available as part of the Request.Params list. Persumably because
"span" is not considered a "editable" element and it's value is not
sent back on postback. Is there a way to force this to happen?

I am developing a composite control which gets rendered within a span
element and I need to retrieve the value of this element on postback
vis Request.Params.

The composite control is not yet "constructed" at the time I want to
retrieve it's value during post-back, so I have lookup the
Request.Params list to get it's value.

-Praveen
 
J

Jc Morin

Hello Praveen,

HtmlHiddenField are good for that. With javascript make a copy of the value
in an hidden field, this one will be posted and be "catchable from server
side code".

Hope that help.
 
P

Praveen

JC,

Thanks for the response.
Yes, I thought about that, but I didn't like that idea for the
following reason:
1) I will have to assing the hidden field a DIFFERENT id, probably
derived from my control's id.
2) Then when I distribute this control (for reuse) I will have to ask
the user to look up the value based on this hidden field's id rather
than the control's id. I found this non-standard and inelegant.

I am concerned that this is the approach I might have to end up taking
though :(

-Praveen
 
J

Jc Morin

Praveen,

You can make composite control with very friendly api and interface that
will hide completely that. You can make a property that will "hide" the
hidden field variable mechanism.

As for Id and reusability, implement INamingContainer and all sub controls
will be assign unique id automatically even if using inside another control,
usercontrol and just multiple instance on the same page.

Hope that help,
 
P

Praveen

JC,

Yes, the user wouldn't have to deal with the hidden fields. But, when
it comes to retrieving the latest "value" they will nevertheless have
to do something like this:

// On Postback at some point:

string compositeControlID = GetCCID(); // I can only get the CC's ID
here based on some logic as the Control itself is not constructed yet.

// Since my composite control control would be using a hidden field to
store the latest value, I will have to look for that hidden field
instead, so:
string hiddenCompositeControlFieldID = compositeControlID +
"valueField"; // "valueField" is advertised to be the suffix you should
add to arrive at the hidden field ID (This got ugly already :( )

// Now retrieve the latest value:
object newValue = Request.Params[hiddenCompositeControlFieldID];

I hope I made myself clear.

Thanks
-Praveen
 
J

Jc Morin

In a perfect Object-Oriented world, the user who want the value of the
hiden-field value control ask the composite control the value (not by using
global Request.Param[]. So only the composite control do the dirty job in a
property that will wrappe the code you type below.
It's only a point of view.
 
P

Praveen

Jc,

Yes, that's true. But, like I mentioned the control is not yet
constructed at this point.

I guess I will have to do it this way.

-Praveen
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top