modifying user control properties on the client.

  • Thread starter Thread starter sonic
  • Start date Start date
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
 
Hi Sonic:

Have you looked at the RegisterHiddenField method? It will allow you
to inject a hidden field into the form from your control.
 
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 )
 
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.
 
Back
Top