Accessing server controls using client scripts....

  • Thread starter Thread starter Stu
  • Start date Start date
S

Stu

Hi,

I am migrating a large app to .Net 2 and am having problems with accessing
hidden fields using javascript.

As I am using masterpages the control names are prefixed with the control
reference of the masterpage '_ctl0_cphMain_MyHiddenField' etc. The app uses
dynamically assigned masterpages to the control name on the page changes
depending on the masterpage being used. There is no

Is there any way of specifying a clientside name to a hidden field, or
adding the additional string to the script automatically?

Thanks in advance,
Stu
 
Have you tried dynamicly generating your script, using the ClientId property
of the controls to get the ids for the hidden fields?
 
In ASP.NET 2.0, you shoud use the functions placed in Page.ClientScript to
register scripts or hidden fields in the page. In the previous version of
ASP.NET theses functions where placed directly on the Page object.
In your example, you can use the folowing statement to register your hidden
field from a UserControl, the Page or from the MasterPage. The client ID of
the field will be preserved with this method :)

Page.ClientScript.RegisterHiddenField("MyHiddenField", "default value");
 
Back
Top