简体   繁体   中英

Setting value of an input hidden field on .aspx page from a user control

Could please anyone tell me how can i set an input hidden field value which is on my .aspx page, from a user control. This user control has couple of drop downs and I can create OnClientSelectedIndexChanged Java Script event handler in my user control but can't figure it out how to set the value in the hidden field which I have on my .aspx page. In other words my .aspx page is rendering this user control and I want to access .aspx page input field from the user control's OnClientSelectedIndexChanged Java Script event. Thanks in advance. Regards,

in the OnClientSelectedIndexChanged function:

document.getElementById('yourHiddenID').value = 'whatever you want';

As a side note, you should bind your javascript functions in javascript, not using the markup properties of the control.

i am not sure if your problem is to access the hidden control in aspx on the client side or the server side.

if on the client side you can write a javascript to OnClientSelectedIndexChanged and update the hidden field of ASPX, all ASCXs part of an ASPX becomes one DOM when it is rendered to the client(browser)

the control names will be prefixed with your ascx tag name and identifier so you might need to use the ClientID to get the id of a control.

on the server side on a postback you can get the values of aspx using the Request.Form, whenever a postback happens all the values of the control are passed in Request.Form collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM