【问题标题】:URL not updating under update panel更新面板下的 URL 未更新
【发布时间】:2012-06-20 21:23:48
【问题描述】:

感谢您的回复。当我单击“首先单击它”链接时,浏览器 URL 会更改。当我点击第二个链接时,它也会更新浏览器中的 URL,但是如果我点击我放在更新面板中的“更新按钮”,它会回发一些服务器功能。

之后,如果我单击任何链接按钮,更新 URL 功能将不起作用。

你有什么想法在更新面板功能后重新初始化 jQuery 代码吗?

我知道当我们使用带有更新面板的 jQuery 时,我们必须在每次页面加载时重新初始化它,但我无法找到该 jQuery 插件的正确 jQuery 函数来调用 asp.net 页面加载事件。

这里是那个jQuery插件的链接

http://code.google.com/p/news21-berkeley/source/browse/branches/v2011/js/jquery.address-1.4.min.js?spec=svn671&r=671

//Page Updating.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UpdatingUrl.aspx.cs" Inherits="UpdateUrl.UpdatingUrl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.6.min.js" type="text/javascript"></script>
    <script src="jquery.address-1.4.min.js" type="text/javascript"></script>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Conditional">
        <ContentTemplate>
            <table class="style1">
                <tr>
                    <td>
                        <a href="#" rel="address:/section/?id=1&amp;name=Ravindra nofollow">Click it first</a>
                    </td>
                <td>
                    <asp:Button runat="server" ID="UpdateButton1" OnClick="UpdateButton_Click" Text="Update" />
                    <asp:Label runat="server" ID="DateTimeLabel1" />
                </td>
            </tr>
            <tr>
                <td>
                    <a href="#" rel="address:/section/?id=2&amp;name=Chauhan nofollow">Click it after Update
                        Button click</a>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

//UpdatingUrl.aspx.cs Page

    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        DateTimeLabel1.Text = DateTime.Now.ToString();
    }     

【问题讨论】:

    标签: jquery asp.net webforms


    【解决方案1】:

    您需要 _endRequest、_beginRequest 处理程序。在后面的代码中添加这个。

    public object endRequestHandle { get; set; }
    
    public object beginRequestHandle { get; set; }
    

    在您的 aspx 页面中,添加以下内容:

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandle);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle);
            function beginRequestHandle(sender, Args) {
               //call any function if you want before Ajax update/request begins
            }
    
            function endRequestHandle(sender, Args) {
             $.getScript("jquery.address-1.4.min.js", function(data, textStatus, jqxhr){});
            }
    

    现在,它可以工作了,脚本将被重新加载并执行。更多关于 $.getScript() here

    【讨论】:

    • 我认为你在正确的轨道上 Leta,但查看问题的示例代码;看起来地址插件不是手动触发的,而是通过解析 rel 属性自动激活的。您可能想要添加到您的答案中,在 endRequestHandle javascript 中,他们还需要手动触发地址插件。
    • 糟糕,没看到,@chouhan_ravi5 编辑了答案,希望有效
    • 酷,不知道 jquery.address 有没有办法手动触发?
    猜你喜欢
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多