我如何通过服务器控件的实际的客户端ID到javascript函数? [英] How do I pass a server control's actual client Id to a javascript function?
问题描述
我有以下的文本框服务器控件在我的网页:
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, <%= txtZip.ClientId %>, txtCity, txtState);" />
我想通过文本框的客户端IDAS第二参数这个JavaScript函数:
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);
}
我如何得到它,在服务器上,评估texbox的控制和到文字字符串传递给Javascript功能?
How do I get it to, on the server, evaluate the texbox's control and to pass that literal string to the Javascript function?
推荐答案
把&LT;%= txtZip.ClientId%GT;
单引号,是这样的
'<%= txtZip.ClientId %>'
<asp:TextBox ID="txtZip" runat="server" onchange="ZipCode_OnChange(this, '<%= txtZip.ClientId %>', txtCity, txtState);" />
更新
请查看这篇文章:的http://www.jagregory.com/writings/how-to-use-clientids-in-javascript-without-the-ugliness/
我也喜欢<一个href=\"http://stackoverflow.com/questions/1362338/how-do-i-pass-a-server-controls-actual-client-id-to-a-javascript-function/1362390#1362390\">this回答
这篇关于我如何通过服务器控件的实际的客户端ID到javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!