[英]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.