Mr_Shaw
asked on
passing data between asp.net (c#) and javascript
Is it possible to pass variables from asp.net to javascript and the other way around?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
so I need to populate a hidden form field with the c# variable and have javascript read it?
You have to pass the ClientID into a Javascript variable, then use that to get the form field by id. The "HiddenFormField" is the ASP.net ID of the field. The field must be set to runat server. I haven't tested this. If you need more information open a new question:
<script type="text/javascript">
var jsFieldId = '<%=HiddenFormField.ClientID%>';
var jsField = document.getElementById(jsFieldId);
var jsFieldValue = jsField.value;
alert(jsFieldValue);
</script>
Assign value to Hidden Fileld which you can access on client side with Javascript like this
var s=document.getElementById(