如何在回发时阻止页面刷新?

时间:2012-05-22 13:23:38

标签: c# javascript jquery

我想在每个div click上显示一个弹出窗口。div会动态创建,每个都是box.I想在弹出窗口中显示一些数据库值。我使用隐藏字段(获取id)作为控制参数在sql datasource中。为了从c#中每次点击获取隐藏的字段值,我在弹出插件的javascript中使用了一些_dopostback。 这会在每次刷新时导致页面加载,因此我无法在每次单击时在弹出窗口中显示正确的值。 我怎样才能避免页面刷新? 我的javascript代码:

在弹出功能中我叫

__doPostBack('TestFunctionPostBack', comp_id);
页面加载中的

c#代码

 this.GetPostBackEventReference(this, string.Empty);

        if (this.IsPostBack)
        {
            string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
            string eventArgument = (this.Request["__EVENTARGUMENT"] == null) ? string.Empty : this.Request["__EVENTARGUMENT"];

            if (eventTarget == "TestFunctionPostBack")
            {               
                HiddenField1.Value = eventArgument;

            }

        }

2 个答案:

答案 0 :(得分:2)

您可以使用AJAX来避免整页回发。

您可以轻松地为部分帖子添加UpdatePanel。或者,更好的是,使用javascript框架,例如jQuery

答案 1 :(得分:0)

使用Ajax调用服务器端方法,然后在UI上呈现内容 请查看以下示例http://weblogs.asp.net/craigshoemaker/archive/2008/09/29/using-jquery-to-call-asp-net-ajax-page-methods.aspx