none
从客户端用js调用服务端方法插入数据!没有反应! RRS feed

  • 问题

  • 我是个初学者!用了ajax.dll! 编译没问题!一直找不到原因!
    function send(){ var txtContent=document.all("content").value;

     if(txtContent=="") return;

    Main.SendMsg(txtContent);

     var div=document.all("show");

     div.innerHTML= Main.find().value+div.innerHTML;

    document.all("content").value=""; }

     

     public partial class Main : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Ajax.Utility.RegisterTypeForAjax(typeof(Main));
               
               
            }
            [Ajax.AjaxMethod()]
            public void SendMsg(string strMsg)
            {
                SqlConnection conn = new SqlConnection("Data Source=ALLEN; Initial Catalog=MyChat;Integrated Security=True");

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SendMsg";
                cmd.Parameters.AddWithValue("@user_from", Session["username"].ToString());

                cmd.Parameters.AddWithValue("@content", strMsg);
              

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
            }

    2011年4月12日 11:50

答案

全部回复