ASP.Net/Asp Control/Image
Версия от 15:30, 26 мая 2010; (обсуждение)
asp:image: change image dynamically
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
If Not IsPostBack Then
imgToView.AlternateText = "Image 1"
imgToView.ImageUrl = "http://www.nfex.ru/style/download.png"
End If
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
imgToView.AlternateText = ddlImages.SelectedItem.Text
imgToView.ImageUrl = ddlImages.SelectedItem.Value
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Creating a Basic Image Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
Select an image to display:<BR>
<asp:dropdownlist
id="ddlImages"
runat=server
>
<asp:listitem text="Image 1" value="http://www.nfex.ru/style/download.png"/>
<asp:listitem text="Image 2" value="http://www.nfex.ru/style/logo.png"/>
<asp:listitem text="Image 3" value="http://www.nfex.ru/style/download.png"/>
</asp:dropdownlist>
<BR>
<asp:linkbutton
id="lnkbutOK"
text="View Image"
onclick="SubmitBtn_Click"
runat="server"
/>
<BR><BR>
<asp:image
id="imgToView"
runat="server"
/>
</Form>
</BODY>
</HTML>
Changing the ImageUrl property dynamically (C#)
<%@ Page Language="C#" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "~/MyImage2.gif";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Image control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" Runat="server" ImageUrl="~/MyImage1.gif" /><br />
<br />
<asp:Button ID="Button1" Runat="server" Text="Change Image"
OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
Changing the ImageUrl property dynamically (VB)
<%@ Page Language="VB" %>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Image1.ImageUrl = "~/MyImage2.gif"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Image control</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" Runat="server" ImageUrl="~/MyImage1.gif" /><br />
<br />
<asp:Button ID="Button1" Runat="server" Text="Change Image"
OnClick="Button1_Click" />
</div>
</form>
</body>
</html>