Implementation of asp.net to display images to a specified Image control

Source: Internet
Author: User

Because the Image control in asp.net is in the System. Web. UI. WebControls namespace, you cannot directly display images through byte [] as in winform.

In this case, we can only save the country. Here is an example of the idea: teacherdetial. aspx is the final page used to display text and images, but because our images need to save the country by curve, another pic. aspx is created here. On the pic. aspx page, the Image is displayed, and the url of the Image control in teacherdetial. aspx is set to pic. aspx. Finally, we completed the requirements.

The code for teacherdetial. aspx is as follows:

Copy codeThe Code is as follows:
<Td height = "25" align = "right"> photo: </td>
<Td>
<Asp: Image ID = "Image1" runat = "server" Width = "80" Height = "80"/>
</Td>

The code for teacherdetial. aspx. cs is as follows:

Copy codeThe Code is as follows:
Private string tid = null;
Protected void Page_Load (object sender, EventArgs e)
{
Tid = Request. Params ["tid"];
This. Image1.ImageUrl = "~ /Teacher/pic. aspx? Tid = "+ tid;
}

In this way, the Image display function is transferred to another page, and our Image control only displays the other page.

The pic. aspx code is very simple. You just need to create a new page.

The pic. aspx. cs code is as follows:

Copy codeThe Code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
String tid = Request. Params ["tid"]. ToString ();
TeacherDao td = new TeacherDao ();
Response. BinaryWrite (td. getPic (tid ));
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.