I am dynamically generating an image as shown below. How can I pass parameters to the ImageGen.aspx
code from Default.aspx
so that the image can be constructed based on that.
//File:ImageGen.aspx
public partial class ImageGen: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bitmap image = new Bitmap(800, 400);
//Code to generate image
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
This image is displayed by:
//File: De开发者_如何学运维fault.aspx
protected void Page_Load(object sender, EventArgs e)
{
Image1.ImageUrl = "~/ImageGen.aspx";
}
You can pass values to page using query string parameters i.e. in default.aspx
call image generator page:
Image1.ImageUrl = "~/ImageGen.aspx?imageId=1";
and in Page_Load method of ImageGen.aspx
retrieve this using
string imageId = Request.QueryString["imageId"];
You need to read about State Maintenance in ASP.NET
Right now for your case Make use of Request query stirng that it
//File: Default.aspx
protected void Page_Load(object sender, EventArgs e)
{
Image1.ImageUrl = "~/ImageGen.aspx?id=1";
}
in second code use it
//File:ImageGen.aspx
public partial class ImageGen: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"];
Bitmap image = new Bitmap(800, 400);
//Code to generate image
image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
精彩评论