如果你把所有的c#代码写在HTML页面就可以!他指定了你的后台类。

解决方案 »

  1.   

    谢谢,能说具体点吗?
    <%@ Page Language="c#" CodeBehind="test_conn_hyl.aspx.cs" AutoEventWireup="true" Inherits="***.***"%>这句怎么改,然后c#语句用什么标签括起来。
      

  2.   

    to:cuike519(studing...) 
    快帮帮我吧,我把代码拷过来是这样的:
    <%@ Page Language="c#" AutoEventWireup="false" %>
    ........
    <%
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace conn{
        public class conn : System.Web.UI.Page {
            protected System.Web.UI.WebControls.TextBox Name;
            public conn() {
                Page.Init += new System.EventHandler(Page_Init);
            }
            private void Page_Load(object sender, System.EventArgs e) {
                // Put user code to initialize the page here
                SqlConnection myCon = new SqlConnection("server=localhost;uid=sa;pwd=;database=store");
                SqlDataReader myRead ;
                SqlCommand myCom = new SqlCommand("select * from customers",myCon);
                if (myCon.State == ConnectionState.Closed) myCon.Open();
                myRead = myCom.ExecuteReader(CommandBehavior.CloseConnection);
                Name.value=myRead["fullname"];
                Response.Write("ok");
            }        private void Page_Init(object sender, EventArgs e) {
                //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                InitializeComponent();
            } #region Web Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent() {    
                this.Load += new System.EventHandler(this.Page_Load);        }
    #endregion
    }
    }
    %>
    前面省略了html代码,编译出错:
    Compiler Error Message: CS1513: } expectedSource Error:Line 20: using System.Web.UI;
    Line 21: using System.Web.UI.WebControls;
    Line 22: using System.Web.UI.HtmlControls;
    Line 23: 
    Line 24: namespace conn{
     
      

  3.   

    就是说如果你不采用代码后置的话(就是把相关的逻辑代码都写到该.aspx页面里面),就可以不写这条语句了。
    如果你采用代码后置就必须要写。
      

  4.   

    <%@ Page Language="c#" AutoEventWireup="false" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.ComponentModel" %>
                         ................
    <script runat="server">
          void Page_Load(Object sender, EventArgs e) 
          {
            // Put user code to initialize the page here
                SqlConnection myCon = new SqlConnection("server=localhost;uid=sa;pwd=;database=store");
                SqlDataReader myRead ;
                SqlCommand myCom = new SqlCommand("select * from customers",myCon);
                if (myCon.State == ConnectionState.Closed) myCon.Open();
                myRead = myCom.ExecuteReader(CommandBehavior.CloseConnection);
                Name.value=myRead["fullname"];
                Response.Write("ok");                     
          }
    </script>
      

  5.   

    to:liuhaixue(小康)
    照你说的改了,还是不行,虽然编译不出错了,但是没有结果,我在page_load事件里加了些简单的测试语句,包括response.write("....."),可是毫无反应。