语言:C#
编译器:Visual Studio 2012
操作系统: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
打开。