ASP编程 PHP编程 JSP编程 NET编程 CGI编程 XML编程 
Google adsense申请技巧本站核心代理域名注册主机业务 快速发布你的买卖域名买卖网站信息 1元注册 cn域名
站长每日新闻导读 √ ·推荐万网空间¥120元 150m 站长网:站长必上的网站网站联盟大全本站代理万网域名55空间120元
 2007-6-15 12:46:04

14个关于ASP.NET热点问题的解答

来源: 字体:[ ]

   12、我是否可以自己创建服务器控件呢?
   
     可以,创作您自己的 ASP.NET 服务器控件很容易。创建简单的自定义控件时,您所要做的只是定义从 System.Web.UI.Control 派生的类并重写它的 Render 方法。Render 方法采用 System.Web.UI.HtmlTextWriter 类型的参数。控件要发送到客户端的 HTML 作为字符串参数传递到 HtmlTextWriter 的 Write 方法。
     例如:
    服务器控件代码(简单显示字符串):


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> 

   
     13、如何在ASP.NET程序中发送邮件呢?
   
     在ASP.NET程序中发送邮件不再象ASP中那样需要组件的支持了,在.NET的框架基类的System.Web.Mail名称空间内包含的MailMessage和SmtpMail类可以实现这个功能。
     例如:
     Dim message As new Mail.MailMessage
     message.From = "web3@163.com"
     message.To = "web3@163.com"
     message.Subject = "测试"
     message.Body = "内容"
     Mail.SmtpMail.SmtpServer = "localhost"
     Mail.SmtpMail.Send(message)
   
     14、我将如何通过ADO.NET读取数据库中的图片并显示它呢?
   
     下面举一个从Microsoft SQL Server的PUB数据库读取图片并显示它的例子:
    <%@ 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> 

 

网站地图 - 域名注册续费虚拟主机代理 - 交易论坛 - 网站投稿 - 广告服务 - 帮助中心 - 联系我们
Copyright ©2003-2007 www.Admin5.com All Rights Reserved