[英]Pass function parameter from c# code behind
I have ASP.NET Web Application Project.In which i want to Pass Value to a function in javascript
from c# code-behind page. 我有ASP.NET Web应用程序项目。我想在其中将值从c#代码隐藏页面传递给
javascript
的函数。
My C# Code Snippet:- 我的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 Code :- JavaScript代码:-
function LoadLoayaltyProgram(PID,ID) {
alert(PID +" "+ ID);
}
When i do Inspect Element on .aspx Page in browser i see code Like : 当我在浏览器中检查.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">
I am not getting any alert on click of "Add" button 单击“添加”按钮没有收到任何警报
In LoadLoayaltyProgram
you are printing consequtive '
. 在
LoadLoayaltyProgram
您正在打印相应的'
。 So, escape the "
with \\"
so you can reuse it with something like this: 因此,请转义
"
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.