ajax实现用户登陆

其实,我以前没有做过ajax,从网上找了一段代码,但不是很完美,遇到了如下问题:

1.编译ASP.NET时,提示“请确保此代码文件中定义的类与“inherits”属性匹配,并且该类扩展的基类(例如Page 或UserControl)是正确的

解决方法: 这是命名空间的问题,在vs2005中是没有命名空间的,但可以自己写上命名空间,可以实现一样的功能

如:

在ASPX页面中的inherits后加入命名空间的名称,如:index_login在index文件夹下写成:inherits="ajaxproloading.index_index_login"即可。ajaxproloading为命名空间,index为文件夹,_index_login为index.aspx文件下的文件,如果在根目录下写:inherits="ajaxproloading.index_login.aspx"(大家可以试一下,我没有试过,在根目录下)即可,

2.说xx名未定义;

在做ajax登陆的时间有两种情况造成的:

(1),开发环境不同:在vs2005下用的是AjaxPro.2.dll,而在vs2003下用的是AjaxPro.dll,如果AjaxPro.dll导入到2005下使用,很可能出现这种情况,所以最好对应使用.

(2).就是命名空间路径问题,如:我在index_login.aspx里,定义namespaceajaxproloading为命名空间,我的文件在index文件夹下,index_login,aspx里:inherits="ajaxproloading.index_login",这样写就会出错,因为我的是在index文件夹下.

(3):一定要记者在web.config里加上:System:web里加上  <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>//因为我用的是AjaxPro.2.dll,而不是AjaxPro.dll,如果用是AjaxPro.dll

大家应该知道怎么样写吧?

 文件如下:

index_login.ascx.:

 <%--<%@ Control Language="C#" AutoEventWireup="true" CodeFile="index_login.ascx.cs" Inherits="index_index_login" %>--%>
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="index_login.ascx.cs" Inherits="ajaxproloading.index_index_login" %>

    <style type="text/css">
<!--
body,td,th {
 font-size: 12px;
}
body {
 margin-left: 0px;
 margin-top: 0px;
 margin-right: 0px;
 margin-bottom: 0px;
}
.index_button {
 font-size: 12px;
 color: #000000;
 line-height:25px;
}  /*黑 有行距*/
.index_white {
 color: #FFFFFF;
 font-size: 12px;
}  /*白*/
.index_white_rude {
 color: #FFFFFF;
 font-size: 12px;
 font-weight: bold;
}  /*粗白*/
.index_red {
 font-size: 12px;
 color: #DE0400;
}  /*红*/
.index_red_rude {
 font-weight: bold;
 font-size: 12px;
 color: #DE0400;
}  /*粗红*/
.index_yellow_rude {
 font-weight: bold;
 font-size: 12px;
 color: #FFCC00;
}  /*粗黄*/
.index_black {
 font-size: 12px;
 color: #000000;
}  /*黑*/
.index_black_rude {
 font-size: 12px;
 color: #000000;
 font-weight: bold;
}  /*粗黑*/
.index_dust{
    color: #3D3D3D;
    font-size: 12px;
 }  /*灰*/
  .index_green{
    font-size: 12px;
 color: #00696B;
}  /*绿*/
 .index_green_rude{
    font-size: 12px;
 font-weight: bold;
 color: #00696B;
}  /*粗绿*/
.index_blue{
 font-size: 12px;
 color: #0000CE;
}  /*蓝*/
.index_blue_rude{
 font-size: 12px;
 font-weight: bold;
 color: #0000CE;
}  /*粗蓝*/
.index_Powder {
    color: #FF3366;
    font-size: 12px;
}   /*粉*/
.index_Powder_rude {
    color: #FF3366;
 font-weight: bold;
    font-size: 12px;
}   /*粗粉*/
.index_from {
 BACKGROUND-COLOR: #FEF5F5;
 font-size: 12px;
 border-right-width: 1px;
 border-bottom-width: 1px;
 border-left-width: 1px;
 border-top-style: solid;
 border-right-style: solid;
 border-bottom-style: solid;
 border-left-style: solid;
 border-top-color: #999999;
 border-right-color: #FFFFFF;
 border-bottom-color: #FFFFFF;
 border-left-color: #999999;
 border-top-width: 1px;
}
.index_input {
 font-size: 12px;
 border: 1px solid #087D7B;
 line-height: 12px;
 padding-top: 3px;
 background-color: #D6DF8C;
 background-image: url(images/index_pic_mainnavbj1.gif);
}
.index_input1 {
 font-size: 12px;
 border: 1px solid #087D7B;
 line-height: 12px;
 padding-top: 3px;
 background-color: #D6DF8C;
 background-image: url(images/index_pic_inputbj.gif);
}
a:link {
 text-decoration: none;
}
a:visited {
 text-decoration: none;
}
a:hover {
 text-decoration: underline;
}
a:active {
 text-decoration: none;
}
.index_green1 {    font-size: 12px;
 color: #006D6B;
}

 

-->
</style>


  <script   language="javascript">    
  function   document.onkeydown()    
  {    
  var   e=event.srcElement; 
    
  if(event.keyCode==13)    
  {    
  document.getElementById("Button3").click();    
  return   false;    
  }    
  }    
  </script>

 

 


   
   <script language=javascript>
  

 

 

 

 

 

function Get_Name(Text1,Text2)
    {
   
    if(Text1.value=="")
    {
    alert("用户名不能为空");
    Text1.focus();
    return false;   
    }
    if(Text2.value=="")
    {
    alert("密码不能为空");
    Text2.focus();
    return false;
   
    }
   
   
   
   
   
   
      var name=document.getElementById("Text1").value;//获取Text1文件框的值.
      var pwd=document.getElementById("Text2").value;
ajaxproloading.index_index_login.GetLogin(name,pwd,CallBackServer);//调用了GetLogin函数
//      Class1.GetLogin(name,pwd,CallBackServer);
     document.getElementById("loading").style.display="block";//显示loading的状态,
     
   
     
    
    }

   function CallBackServer(res)
    {
     var success=res.value;
     document.getElementById("loading").style.display="none";//显示loading的状态,
   
   
    if(success)
    {
       //document.getElementById("ss").innerHTML="登陆成功";
     //alert("登路成功");
    
    alert("登陆成功");window.location.replace("../wwwroot/member_page/Member_Index.aspx?name="+document.getElementById("Text1").value+"&&pwd="+document.getElementById("Text2").value+"");
     }
     else
    {
   
     //document.getElementById("ss").innerHTML="登陆失败";
//    alert("登路失败");

   
    alert("登陆失败");
    }
      }   </script>
 
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr height="5">
            <td>
           
            </td>
        </tr>
           <tr>
              <td width="28" align="center" style="height: 24px"><img src="../images/index_pic_login.gif" width="17" height="12" /></td>
              
               
               <td align="left" valign="middle" colspan="2" style="height: 24px" >
             
                   用户名:<input id="Text1" style="width: 95px" type="text" />
                   密码:<input id="Text2" style="width: 107px" type="password" />
      
                  <input id="Button3" class="index_input"  type="button"   οnclick="Get_Name(Text1,Text2);"value="登陆" />
                  <div id="loading"  style="display:none">
                 <img src="images/loading.gif" style="width: 19px; height: 19px"/>您正在登陆,请稍候....</div>
                 <%--<div id="ss"></div>--%><%-- 
        <div id="loading" style="position:absolute; left:66px; top:9px;  width: 167px; height: 27px; display:none;"><img src="images/loading.gif" />您正在登陆,请稍侯</div>
--%><%--  <asp:Button ID="Button3" runat="server" class="index_input" Text="登陆" OnClick="Get_Name()" />           --%><%--  <asp:Label ID="lbSuccess" runat="server"></asp:Label>--%></td>
           
              <td width="74" align="center" style="width: 56px; height: 24px;">
                  &nbsp;<asp:Button ID="Button2" runat="server" class="index_input" Text="注 册" OnClick="Button2_Click" CausesValidation="False"/>
            </td>
              <td width="73" align="center"  onMouseOver="fun(fbLayer4,'show')" onMouseOut="fun(fbLayer4,'hide')" style="height: 24px"><input  name="Submit3" type="submit" class="index_input" value="&#25105;&#35201;&#21457;&#24067;" />&nbsp;
             
         <script language="JavaScript" type="text/JavaScript">
        function fun(idname,ac){
        ac=='show'?idname.style.visibility="visible":idname.style.visibility="hidden";
        }
        </script>
           <div id="fbLayer3" style="position:absolute;">
         <div id="fbLayer4" style="position:absolute; left:-86px; top:20px; visibility: hidden; width: 106px; height: 151px;">
      <table  border="0" cellpadding="0" cellspacing="1" bgcolor="#ffffff" style="width: 104px; height: 166px;">
       <tr>
        <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="width: 102px"><a href="../member_page/user/Minvite/Minvite_issue.aspx" class="style4">招商信息发布</a>
        </td></tr>
        
          <tr>
         <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="height: 14px; width: 102px;"><span class="style4"><a href="../member_page/user/mdealer/mdealer_issue.aspx"   class="link02">代理信息发布</a></span></td></tr>
        <tr>
      <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="width: 102px"><span class="style4"><a href="../member_page/user/Mstock/Mstock_issue.aspx" class="link02">求购信息发布</a></span></td> </tr>
       
     <tr>
      <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="width: 102px"><span class="style4"><a href="../member_page/user/mprovide/mprovide_issue.aspx" class="link02">供应信息发布</a></span></td> </tr>
       <tr>
        <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="width: 102px"><span class="style4"><a href="../member_page/user/mcooperate/mcooperate_issue.aspx" class="link02">合作信息发布</a></span></td></tr>
     
      <tr>
      <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="width: 102px"><span class="style4"><a href="../member_page/user/Mattorn/Mattorn_issue.aspx" class="link02">转让信息发布</a></span></td></tr>
    
     <tr>
   <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="height: 14px; width: 102px;"><a href="../member_page/Mhickey_issue_mangage/Mhickey_issue.aspx" class="style4">医疗器械发布</a></td></tr>
  
     <tr>
       <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="height: 14px; width: 102px;"><span class="style4"><a href="../member_page/Mjob_issue/Mjob_issue.aspx" class="link02">招聘信息发布</a></span></td>
            </tr>
 <tr>
       <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="width: 102px" ><span class="style4"><a href="../member_page/person_issue/person_jssue.aspx" class="link02">求职信息发布</a></span></td>
     </tr>
    <tr>
       <td align="center" bgcolor="#FFCCCC" onMouseOut="this.style.background='#FFCCCC'" onMouseOver="this.style.background='#F7AA52'" style="width: 102px" ><span class="style4"><a href="../member_page/j_member/Mzb_jssue.aspx" class="link02">招标/中标信息发布</a></span></td>
     </tr>
 
    <tr>
     </tr>
    </table>
             </div>
     </div>
             </td>
              <td width="5" align="right" class="index_green1" style="height: 24px">&nbsp;</td>
              <td align="center" class="index_green1" style="width: 33px; height: 24px;"><img src="../images/index_pic_sousuotb.gif" width="16" height="11" /></td>
              <td align="center" class="index_red" style="width: 62px; height: 24px;">快速搜索:</td>
              <td align="center" style="width: 123px; height: 24px;">
                  <asp:TextBox ID="TextBox3" runat="server" Width="100px"  class="index_from"></asp:TextBox>
             </td>
              <td align="center" style="width: 82px; height: 24px;">
          
                  <asp:DropDownList ID="DropDownList1" runat="server"  class="index_from">
                  <asp:ListItem>--请选择--</asp:ListItem>
                      <asp:ListItem Value="zhaoshang">招商信息</asp:ListItem>
                      <asp:ListItem Value="daili">代理信息</asp:ListItem>
                      <asp:ListItem Value="qiugou">求购信息</asp:ListItem>
                      <asp:ListItem Value="gongying">供应信息</asp:ListItem>
                      <asp:ListItem Value="zhuanrang">转让信息</asp:ListItem>
                      <asp:ListItem Value="hezuo">合作信息</asp:ListItem>
                      <asp:ListItem Value="zixun">医药咨询</asp:ListItem>
                      <asp:ListItem Value="rencai">医药人才</asp:ListItem>
                  </asp:DropDownList>
              </td>
              <td width="75" align="center" style="height: 24px">
                  <asp:Button ID="Button4" runat="server" class="index_input" Text="搜 索" OnClick="Button4_Click" CausesValidation="False" />
             
             </td>
      </tr>
                 <tr height="4">
            <td>
           
            </td>
            </tr>
</table>
 


//index_login.aspx

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace ajaxproloading
{

    public partial class index_index_login : System.Web.UI.UserControl
{
    public string str_sql, user_name, user_pwd,kongzhi,sousuo;

    protected void Page_Load(object sender, EventArgs e)
    {

        AjaxPro.Utility.RegisterTypeForAjax(typeof(index_index_login));
     
    
    }
    [AjaxPro.AjaxMethod]


    public bool GetLogin(string username, string userpwd)
    {
        System.Threading.Thread.Sleep(3000);
        //以下是调用数据库,实现验证的
        SqlConnection con = new SqlConnection("server=.;database=Hr;uid=sa;pwd=");
        con.Open();
        SqlCommand com = new SqlCommand();
        com.CommandText = "select User_name,User_pwd,User_id from yy3721_user where User_name='" + username + "' and User_pwd='" + userpwd + "'";
        com.Connection = con;
        SqlDataReader da = com.ExecuteReader();
        if (da.Read())
        {

            //Session["User_name"] = da["User_name"].ToString().Trim();
            //Session["User_id"] = da["User_id"].ToString();
        
           con.Close();
            return true;
        }
        else
        {
            con.Close();
            return false;

        }

    }

 
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("/member_page/user/member/member_service.html");


    }

   protected void Button4_Click(object sender, EventArgs e)
    {
        sousuo=DropDownList1.SelectedValue.ToString();
        if (sousuo == "zhaoshang")
        {
            Response.Write("招商");
            Response.Redirect("invite/index.aspx?text="+TextBox3.Text+"");
        }
        else if (sousuo == "daili")
        {
            Response.Redirect("dealer/index.aspx?text="+TextBox3.Text+"");
        }
        else if (sousuo == "qiugou")
        {
            Response.Redirect("stock/index.aspx?text=" + TextBox3.Text + "");
        }
        else if (sousuo == "gongying")
        {
            Response.Redirect("provide/index.aspx?text=" + TextBox3.Text + "");
        }
        else if (sousuo =="zhuanrang")
        {
            Response.Redirect("attorn/index.aspx?text="+TextBox3.Text+"");
        }
        else if (sousuo =="hezuo")
        {
            Response.Redirect("cooperate/index.aspx?text=" + TextBox3.Text + "");
        }
        else if (sousuo =="zixun")
        {
            Response.Redirect("news/index.aspx");
        }
        else if (sousuo =="rencai")
        {
            Response.Redirect("curative_job/index.aspx?s_text_jobname=" + TextBox3.Text +"&province=");
        }
    }


        protected void Get_Name(object sender, EventArgs e)
        {

        }
        }
}

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值