0

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

1
  • How this field is stored? In a view state, hidden fild or else? Commented Dec 3, 2009 at 22:31

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
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.
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.
Dohh, worked a treat Restuta, if only your comment was n answer
0
  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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.