Simple.vb:
Imports System Imports System.Web Imports System.Web.UI Namespace SimpleControlSamples Public Class SimpleVB : Inherits Control Protected Overrides Sub Render(Output As HtmlTextWriter) Output.Write("<H2>欢迎使用控件开发!</H2>") End Sub End Class End Namespace 引用文件Simple.aspx: <%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %> <html> <body> <form method="POST" action="Simple.aspx" runat=server> <SimpleControlSamples:SimpleVB id="MyControl" runat=server/> </form> </body> </html> |
<%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Drawing.Imaging" %> <%@ Import Namespace="System.IO" %> <script language="VB" runat="server"> Sub Page_load(Sender as Object, E as EventArgs) dim stream as new MemoryStream dim connection as SqlConnection connection=new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=") try connection.Open() dim command as SqlCommand command = new SqlCommand ("select logo from pub_info where pub_id=''0736''", connection) dim image as byte() image = command.ExecuteScalar () stream.Write (image, 0, image.Length) dim imgbitmap as bitmap imgbitmap = new Bitmap (stream) Response.ContentType = "image/gif" imgbitmap.Save (Response.OutputStream, ImageFormat.Gif) Finally connection.Close() stream.Clse() End Try End Sub </script> |