views:

46

answers:

2

Hi

This I can't work out

I have ASP.Net user control,which is basically two drop downs, that has a public property Index which is calculated from the drop downs, and works fine

I need to access the value of 'Index' from javascript, but accessing via getElementById was completely wrong, can anybody point me in a better direction

Cheers

+2  A: 

The property you're talking about is a server side thing and has no presence in Javascript. Basically, whatever ASP.NET does on the server will generate a single HTML page containing a bunch of HTML tags. The browser is not aware of the user control being a single entity at all.

You should calculate the property on the client by looking up the ID of the drop down directly in Javascript. You can do find out the client ID of the drop down by getting its ClientID property.

Mehrdad Afshari
Got that, unfortunately the value I cannot be calculated from the drop down (or both) directly, if it's not possible to post index to the page,or read index from the control,will have to go about it differently.
spacemonkeys
Isn't it possible to print the index in a Javascript variable? If it's not going to change until a postback is made, this can work.
Mehrdad Afshari
It is possible to "post" index to the page and possible to read index from the control. All you need is to create a hidden field into your control - <input type="hidden"ID="myIndex" /> and store you value in it. Then you can access to your value by getElementById.
Restuta
Dohh, worked a treat Restuta, if only your comment was n answer
spacemonkeys
A: 
  1. Create javascript method as a string from server side and use index property to create script string.
  2. register string on which event it is required. you can take help from following link to register javascript:
    http://msdn.microsoft.com/en-us/library/aa479011.aspx
  3. If any server side control is used in javascript method, use ClientID property as ID of the control.

Hope, It helps

Brij