setting a form control from javascript

  • Thread starter Thread starter Andy Fish
  • Start date Start date
A

Andy Fish

Hi,

I want to generate a value with javascript and include it in the form
postback for a web form.

based on my previous web development experience, I think I need an <input
type=hidden> on the page. However, to fit in properly with the web forms
paradigm, I would like this to be a proper asp.net server side control
rather than just generating it in the HTML.

I have found I can do this OK with a text box as long as it's visible; if I
make the text box hidden it is no longer rendered in the HTML (and so i
can't set it from javascript). What's the best way to achieve what I'm
trying to do?

Andy
 
Can't you just add a runat=server and an id to the HTML control?

<input type="hidden" runat="server" id="id1">

OR generate it at run-time using a PlaceHolder:

<asp:PlaceHolder ID="ph" Runat="server" />

Dim myInputHidden As New HtmlControls.HtmlInputHidden
ph.Controls.Add(myInputHidden)

Not sure what you gain by using the placeholder method though. Escepcially
because the ClientID would not be known at design time for use with your js
code.

Greg
 
Greg Burns said:
Can't you just add a runat=server and an id to the HTML control?

<input type="hidden" runat="server" id="id1">

thanks, I didn't realise you could do this.

I'm a bit new to web forms and I thought you had to put the controls on in
designer mode for them to be accessible as controls on the server

Andy
 
thanks, I didn't realise you could do this.

I'm a bit new to web forms and I thought you had to put the controls on in
designer mode for them to be accessible as controls on the server

ah, now I look a bit closer, I see you can switch the toolbox to insert HTML
elements as well as webforms controls. slowly I'm getting the hang of it.
:-)
 
Back
Top