开发者

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

I show modal popup window in default.aspx page so:

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

How to call "grdReportKeywordsRefresh" method with parameter "report_id" right?

Why controls of Default.aspx page are not displayed in popup 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:

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


People are right, you're mixing stuff :)

It should go like this:

<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)

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)

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


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.

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.

Simon


Where is report_id defined? You cannot use variables that are set in javascript because server side code (<%= %>) gets executed when the page is rendered by the server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜