[英]Manually change part of an image URL
I am using an .aspx file along with a C#(aspx.cs) file. 我正在使用.aspx文件和C#(aspx.cs)文件。 The goal is to enter a number in the text box and change a section of a photo's URL, so that when it's submitted it will bring up a different photo.
目的是在文本框中输入数字并更改照片URL的一部分,以便在提交照片时将显示另一张照片。
The .aspx code is: .aspx代码是:
<form id="form1" runat="server">
<form action="demo_reqquery.asp" method="get">
Enter Pic number: <input type="text" name="pnumber" size="20" />
<input type="submit" value="Submit" />
</form>
<div class="logo2">
<asp:Image ImageUrl="http://www.website.com/pic0001.jpg" runat="server" />
</div>
</form>
The user enters "pnumber" 0005 in the text box and submits. 用户在文本框中输入“ pnumber” 0005并提交。 Then the 0001 in the URL is replaced with the 0005 entered bringing up photo: " http://www.website.com/pic0005.jpg "
然后将URL中的0001替换为输入的0005,显示照片:“ http://www.website.com/pic0005.jpg ”
If you are ok to change the elements of your form, 如果您可以更改表单的元素,
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<asp:Image ID="Image1" runat="server" />
</div>
</form>
Code behind would be 后面的代码是
protected void Button1_Click(object sender, EventArgs e)
{
Image1.ImageUrl = "http://www.website.com/pic" + TextBox1.Text + ".jpg";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.