简体   繁体   English

如何使用 Jquery 的参数调用 c# 方法? ASP.Net 2.0

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

I show modal popup window in default.aspx page so:我在 default.aspx 页面中显示模态弹出窗口 window 所以:

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

Jquery function: 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();
            });
        });

How to call "grdReportKeywordsRefresh" method with parameter "report_id" right?如何使用参数“report_id”调用“grdReportKeywordsRefresh”方法?

Why controls of Default.aspx page are not displayed in popup window?为什么 Default.aspx 页面的控件不显示在弹出窗口 window 中?

report_id:报告编号:

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

grdReportKeywordsRefresh method: grdReportKeywordsRefresh 方法:

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

You're mixing client and server code.您正在混合客户端和服务器代码。

You're also loading another page altogether into your pop-up, so it's not surprising it's not showing anything from default.aspx.您还将另一个页面完全加载到您的弹出窗口中,因此它没有显示来自 default.aspx 的任何内容也就不足为奇了。

You could set a value in a hidden field when you close the pop-up, then force the postback & on the server, check if the hidden field value is set and call the function if it is.您可以在关闭弹出窗口时在隐藏字段中设置一个值,然后在服务器上强制回发 &,检查是否设置了隐藏字段值,如果是则调用 function。

Simon西蒙

People are right, you're mixing stuff:)人们是对的,你在混合东西:)

It should go like this:它应该像这样 go :

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

in codebehind (using VB.NET, if you use C#, I'll change it)在代码隐藏中(使用 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# (just frome head) c#(仅来自头部)

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

Where is report_id defined? report_id 在哪里定义? You cannot use variables that are set in javascript because server side code (<%= %>) gets executed when the page is rendered by the server.您不能使用在 javascript 中设置的变量,因为服务器端代码 (<%= %>) 会在服务器呈现页面时执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM