Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
96
rated 0 times [  97] [ 1]  / answers: 1 / hits: 55447  / 15 Years ago, tue, september 1, 2009, 12:00:00

I have the following textbox server control in my web page:



<asp:TextBox ID=txtZip runat=server onchange=ZipCode_OnChange(this, <%= txtZip.ClientId %>, txtCity, txtState);/>


When the page renders, it is built including the following:



<input name=txtZip type=text id=txtZip onchange=ZipCode_OnChange(this, &lt;%= txtZip.ClientId %>, txtCity, txtState); />


I'm trying to pass the text box's client IDas the 2nd param to this Javascript function:



function ZipCode_OnChange(txtZipCode, ClientId) {
var ret;
ret = WebService.GetCityAndState(txtZipCode.value, OnComplete1, OnError, ClientId);
}


How do I get it to, on the server, evaluate the texbox's control and to pass that literal string to the Javascript function?


More From » asp.net

 Answers
16

Put the <%= txtZip.ClientId %> between single quotes, to be like this:



'<%= txtZip.ClientId %>'


<asp:TextBox ID=txtZip runat=server onchange=ZipCode_OnChange(this, '<%= txtZip.ClientId %>', txtCity, txtState); />


Update



Please check this article: http://www.jagregory.com/writings/how-to-use-clientids-in-javascript-without-the-ugliness/



Also I like this answer


[#98787] Thursday, August 27, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mira

Total Points: 460
Total Questions: 108
Total Answers: 99

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
mira questions
;