[英]pass parameter to one function in the code behind in C# from javascript
[英]Pass function parameter from c# code behind
我有ASP.NET Web应用程序项目。我想在其中将值从c#代码隐藏页面传递给javascript
的函数。
我的C#代码段:-
//Here td_Output is TableCell
td_Output.Text = "<input type='button' style='font-size:11px;' onclick='LoadLoayaltyProgram(1,'"+Convert.ToString(Request.Form["Program"])+"');' class='ui-button ui-widget ui-state-default ui-corner-all' role='button' value='Add' />";
JavaScript代码:-
function LoadLoayaltyProgram(PID,ID) {
alert(PID +" "+ ID);
}
当我在浏览器中检查.aspx页面上的元素时,我看到类似以下代码:
<input type="button" style="font-size:11px;" onclick="LoadLoayaltyProgram(1," pid112002');'="" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" value="Add">
单击“添加”按钮没有收到任何警报
在LoadLoayaltyProgram
您正在打印相应的'
。 因此,请转义"
with \\"
以便可以将其与以下内容一起重复使用:
string program = Server.UrlEncode(Request.Form["Program"] ?? string.Empty);
td_Output.Text = String.Format("<input type='button' style='font-size:11px;' onclick='LoadLoayaltyProgram(1, \"{0}\");' class='ui-button ui-widget ui-state-default ui-corner-all' role='button' value='Add' />", program);
onclick="LoadLoayaltyProgram(1," pid112002');'=""
这看起来很奇怪,不应该是这样吗?
onclick="LoadLoayaltyProgram(1, 'pid112002')"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.