mcoolbeth
mcoolbeth

Reputation: 477

Interacting with ASP.NET properties in Javascript

I am try in to get the ClientID of one of my server controls to appear in a Javascript in my aspx page.

Obviously I am going about it the wrong way, but my intent should be made clear in the following:

doSomethingFirst();
var hid = "<% Response.Write(HidingField.ClientID) %>";
doSomethingElse(hid);

Any advice?

Thanks.

Upvotes: 0

Views: 89

Answers (3)

mcoolbeth
mcoolbeth

Reputation: 477

It was the stupid missing semicolon.

I apologized for wasting everyone's time.

Upvotes: 0

CodingGorilla
CodingGorilla

Reputation: 19872

I'm doing a bit of guessing about your intent, so forgive me if I've guessed wrong, but I think this is what you're looking for:

doSomethingFirst();
var hid = document.getElementById('<%= HidingField.ClientID %>');
doSomethingElse(hid);

I assuming your intent is to get a reference to the DOM element represented by the client id so that you can then do some sort of javascript operation on that element.

Upvotes: 1

Chris
Chris

Reputation: 2991

Have you tried:

var hid = "<%= HidingField.ClientID %>";

making sure that "HidingField" is the ID of the server control?

Upvotes: 0

Related Questions