ASP更新面板停止工作

时间:2012-09-18 12:57:58

标签: asp.net ajax

语言:C#
编译器:Visual Studio 2012
O / S:Windows 7 Home Premium

我一直在内容页面上使用UpdatePanel一段时间,根据文本框中的文字更新图片。
到目前为止,这一切都奏效了。目前,页面完全重新加载以显示图像,而不是部分回发。

.aspx代码

<asp:UpdatePanel ID="UpdatePanel2" runat="server">
            <ContentTemplate>
                <asp:Image ID="imgProfilePicture" runat="server" />
                <br />
                <asp:TextBox ID="txtImageLocation" runat="server" AutoPostBack="True" MaxLength="1000" CssClass="styleTextBoxCenter" Width="170px" OnTextChanged="txtImageLocation_TextChanged"></asp:TextBox><br />
                <div style="padding-left: 4px;">
                    <asp:Label ID="lblImageUrl" runat="server" Text="Image URL" CssClass="styleLabelWatermark"></asp:Label>
                </div>
            </ContentTemplate>

            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="txtImageLocation" EventName="TextChanged" />
            </Triggers>
        </asp:UpdatePanel>

.cs代码

protected void txtImageLocation_TextChanged(object sender, EventArgs e)
    {
        if(string.IsNullOrEmpty(txtImageLocation.Text))
        {
            imgProfilePicture.ImageUrl = RemoteReaderPlugin.Current.CreateSignedUrl("http://i.minus.com/iNQ7wK2opRJT1.gif",
                                                                                    new ResizeSettings(
                                                                                        "width=183&format=png"));
            lblImageUrl.Text = "Image URL";
            return;
        }
        if (!@txtImageLocation.Text.StartsWith("http://"))
        {
            @txtImageLocation.Text = "http://" + @txtImageLocation.Text;
        }
        WebRequest request = WebRequest.Create(@txtImageLocation.Text);

        try
        {
            request.GetResponse();
            imgProfilePicture.ImageUrl = RemoteReaderPlugin.Current.CreateSignedUrl(@txtImageLocation.Text,
                                                                                    new ResizeSettings(
                                                                                        "width=183&s.roundcorners=10"));
            lblImageUrl.Text = "Image Verified";
            lblImageUrl.ForeColor = System.Drawing.Color.Green;
        }
        catch (Exception)
        {
            imgProfilePicture.ImageUrl =
                RemoteReaderPlugin.Current.CreateSignedUrl(
                    "http://i.minus.com/ibwhXZ9wLo1mOz.jpg",
                    new ResizeSettings("width=183&s.roundcorners=10"));
            lblImageUrl.Text = "Invalid URL";
            lblImageUrl.ForeColor = System.Drawing.Color.Red;
            txtImageLocation.Focus();
        }
    }

我无法想到我已经改变的任何内容,页面仍然有ScriptManager

1 个答案:

答案 0 :(得分:1)

事实证明,如果您将“全局”Routein设置为UpdatePanel,则Global.asax上的所有功能都会丢失。

当我添加routes.MapPageRoute("", "{address}", "~/{address}.aspx");时,问题就开始了。

移除后,ajax面板工作。