1. display images generated by code
Put the generated image code in An ASPX page and write the image to the output stream in the pageload event:
Private void page_load (Object sender, system. eventargs e ){
String code = request. Params ["code"];
Bitmap image = drawimage (CODE );
Response. contenttype = "image/GIF ";
Image. Save (response. outputstream, system. Drawing. imaging. imageformat. GIF );
Response. End ();
}
To reference an image, set the image URL to the ASPX page of the generated image:
Imagecode. imageurl = "codeimage. aspx? Code = "+ code;
2. Use System. Web. httpcontext. Current to implement common page methods, such:
Public class webapp {
Public static void showmessage (string message ){
Httpcontext. Current. response. Write ("<script language = JavaScript> alert ('" + message + "') </SCRIPT> ");
}
Public static string currentuser {
Get {
Return httpcontext. Current. session ["userid"] + "";
}
}
}
3. Compile the Javascript script file into an embedded resource in a custom web control, read the script from the resource, and register it.
Public class res {
Public static streamreader getstream (type, string name ){
// Assembly = assembly. getassembly (type );
Assembly = type. assembly;
Stream stream = assembly. getmanifestresourcestream (type, name );
Return new streamreader (Stream );
}
}
Public class scriptcontrol: Control {
/// <Summary>
/// Register client script block
/// </Summary>
/// <Param name = "control"> custom web control </param>
/// <Param name = "scriptfile"> resource script file name </param>
Public void registerscript (string scriptfile ){
If (! This. Page. isclientscriptblockregistered (scriptfile )){
Streamreader reader = res. getstream (this. GetType (), scriptfile );
Using (Reader ){
String script
= "<Script language =/" javascript/"type =/" text/JavaScript/">/R/n <! --/R/N"
+ Reader. readtoend ()
+ "/R/N // -->/R/n </SCRIPT> ";
This. Page. registerclientscriptblock (scriptfile, script );
}
}
}
}
[Defaultproperty ("text "),
Toolboxdata ("<{0}: showdialoglistbox runat = Server> </{0}: showdialoglistbox>")]
Public class showdialoglistbox: scriptcontrol {
......
Protected override void oninit (eventargs e ){
This. registerscript ("endelistbox. js ");
}
......
}
4. Define the default page inheritance type in the web. config file.
<Pages pagebasetype = "msdn. Page"/>