簡體   English   中英

如何使用 Jquery 的參數調用 c# 方法? ASP.Net 2.0

[英]How to call c# method with parameter from Jquery? ASP.Net 2.0

我在 default.aspx 頁面中顯示模態彈出窗口 window 所以:

<a id="popup" href="../Popup/Keywords.aspx">edit</a>

Jquery function:

$(document).ready(function () {
            $('a#popup').live('click', function (e) {

                var page = $(this).attr("href")

                var $dialog = $('<div></div>')
                .html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>')
                .dialog({
                    autoOpen: false,
                    modal: true,
                    height: 450,
                    width: 'auto',
                    title: "Edit Employee",
                    buttons: {
                        "Close": function () { $dialog.dialog('close'); }
                                },
                    close: function (event, ui) {


                    __doPostBack('<%= grdReportKeywordsRefresh(report_id) %>', '');
                    }
                });
                $dialog.dialog('open');
                e.preventDefault();
            });
        });

如何使用參數“report_id”調用“grdReportKeywordsRefresh”方法?

為什么 Default.aspx 頁面的控件不顯示在彈出窗口 window 中?

報告編號:

private String r_id;
public Int32 report_id
{
    get { return r_id != null ? Convert.ToInt32(r_id) : 0; }
    set { r_id = value; }
}

grdReportKeywordsRefresh 方法:

protected void grdReportKeywordsRefresh(int report_id)
{
    grdKeywords.DataSource = conn.GetKeywordsByRepId(report_id);
    grdKeywords.DataBind();
}

您正在混合客戶端和服務器代碼。

您還將另一個頁面完全加載到您的彈出窗口中,因此它沒有顯示來自 default.aspx 的任何內容也就不足為奇了。

您可以在關閉彈出窗口時在隱藏字段中設置一個值,然后在服務器上強制回發 &,檢查是否設置了隱藏字段值,如果是則調用 function。

西蒙

人們是對的,你在混合東西:)

它應該像這樣 go :

<script type="text/javascript">
this is what you call:
  __doPostBack('updateMyGrid', '')
</script>

在代碼隱藏中(使用 VB.NET,如果您使用 C#,我會更改它)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If Page.IsPostBack AndAlso Page.Request("__EVENTTARGET") = "updateMyGrid" Then
    'rebind your grid here
  End If
End Sub

c#(僅來自頭部)

protected void Page_Load(object sender, EventArgs e) {
  if(IsPostBack && Page.Request["__EVENTTARGET"] == "updateMyGrid") {
    //rebind here
  }
}

report_id 在哪里定義? 您不能使用在 javascript 中設置的變量,因為服務器端代碼 (<%= %>) 會在服務器呈現頁面時執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM