spacemonkeys
spacemonkeys

Reputation: 1749

ASP.NET user control and accessing a property from Javascript?

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

Upvotes: 0

Views: 2392

Answers (2)

Brij
Brij

Reputation: 6122

  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

Upvotes: 0

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421988

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.

Upvotes: 2

Related Questions