Saturday, March 24, 2012

Access a server-side control from JavaScript in beta 2

Sorry if this has been asked already, I tried search but no luck.

Okay, I have a server-side control defined as


<asp:Textbox id="textboxonserver" runat="server" />

What I want to achieve is to set the value of this control from client side javascript. document.getElementById("textboxonserver") won't work since the real id on page is something like ctrl$palceholder$textboxonserver. Tried $find, still nothing.

I know I can get the value by doing something like


My.prototype = {

_textboxid: null

...


Then set the textboxid = this.textboxonserver.ClientID inside the pageload() loop. But isn't this a bit overkill just for that purpose.

Thanks

nvm...i found the answer myself:

inside my javascript I can actually do this:

var txtboxid = "<%= textboxonserver.ClientID %>";

then use document.getElementById(txtboxid) to get the object in DOM tree. Just not sure if this is the elegant way to do this although it works..


ugh...sorrySad problem still stands..

No comments:

Post a Comment