modifying user control properties on the client.

S

sonic

I came across a problem today that seems very trivial however i did not
yet solve it elegantly.

Normally, when i need to pass values between server and javascript, I
create a server control such as textbox or htmlInputHidden and
update/read it on both sides.

However, I am developing a user control, which does not have a UI
component, and so I cannot just drop a TextBox on the page and declare
it as protected inside of my control and access it. ( I am aware that I
can add a UI component such as ASCX file but I am not doing it in this
example )

The only thing I can do it seems is override Render event, and render
any elements i would like to appear on the browser. However I have not
yet figured out how to read those controls back on post back, since
they need to be re-created every time.

What is the most elegant solution in this example to pass variables
from javascript back to the server ?
TIA
 
S

Scott Allen

Hi Sonic:

Have you looked at the RegisterHiddenField method? It will allow you
to inject a hidden field into the form from your control.
 
S

SoniC SouL

hey,
thanks for responding.
I have not looked at that. Is it any different than overriding Render
event and doing
myHiddenField.RenderControl( writer ). because i have no problem adding
the hidden fields to the page.

my issue is with reading the values back on postback.

Even if i registerhiddenfield is there a way that the value from that
field will be persisted on the postback in a server control manner ? (
w/out resorting to tricks such as html form postback value read )
 
S

Scott Allen

Yes - it should be persisted on postback. Perhaps if you share the
code you are using to retrieve the value we can pick out what is going
wrong.
 

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