| 发表于:2007-03-20 19:29:21 楼主 |
两个网页,网页1是登录界面,正确的话转到网页2,在网页2上显示登录名,调试没问题,但是真正登录时却只是显示网页1,其他没有任何显示,麻烦高手帮忙看看 以下是代码, webform1.aspx: <%@ page language= "c# " codebehind= "webform1.aspx.cs " autoeventwireup= "false " inherits= "_1.webform1 " %> <!doctype html public "-//w3c//dtd html 4.0 transitional//en " > <html> <head> <title> webform1 </title> <meta name= "generator " content= "microsoft visual studio .net 7.1 "> <meta name= "code_language " content= "c# "> <meta name= "vs_defaultclientscript " content= "javascript "> <meta name= "vs_targetschema " content= "http://schemas.microsoft.com/intellisense/ie5 "> </head> <body ms_positioning= "gridlayout "> <form id= "form1 " method= "post " runat= "server "> <font face= "宋体 "> <asp:button id= "btn_login " style= "z-index: 106; left: 384px; position: absolute; top: 200px " runat= "server " text= "登录 "> </asp:button> </font> <table id= "table2 " style= "z-index: 102; left: 256px; position: absolute; top: 96px " cellspacing= "1 " cellpadding= "1 " width= "300 " border= "1 "> <tr> <td style= "width: 62px "> 用户名 </td> <td> <asp:textbox id= "textbox1 " runat= "server " width= "160px "> </asp:textbox> </td> </tr> <tr> <td style= "width: 62px "> 密 码 </td> <td> <asp:textbox id= "textbox2 " runat= "server " width= "160px " textmode= "password "> </asp:textbox> </td> </tr> </table> <asp:label id= "label1 " style= "z-index: 103; left: 304px; position: absolute; top: 48px " runat= "server "> 网页1 </asp:label> </form> </body> </html> webform1.aspx.cs: using system; using system.collections; using system.componentmodel; using system.data; using system.drawing; using system.web; using system.web.sessionstate; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.htmlcontrols; using system.data.sqlclient; namespace _1 { /// <summary> /// webform1 的摘要说明。 /// </summary> public class webform1 : system.web.ui.page { protected system.web.ui.webcontrols.textbox textbox1; protected system.web.ui.webcontrols.textbox textbox2; protected system.web.ui.webcontrols.button btn_login; protected system.web.ui.webcontrols.label label1; private void page_load(object sender, system.eventargs e) { // 在此处放置用户代码以初始化页面 } #region web 窗体设计器生成的代码 override protected void oninit(eventargs e) { // // codegen: 该调用是 asp.net web 窗体设计器所必需的。 // initializecomponent(); base.oninit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void initializecomponent() { this.load += new system.eventhandler(this.page_load); } #endregion private void btn_login_click(object sender, system.eventargs e) { sqlconnection sqlconn = new sqlconnection( "data source=(p4);database=1;uid=sa;pwd= "); sqlconn.open(); sqlcommand sqlcom = sqlconn.createcommand(); sqlcom.commandtext = "select name from user where name= ' " + textbox1.text + " ' and regiondescription= ' " + textbox2.text + " ' "; int count = convert.toint32(sqlcom.EXECutescalar());//获取sql语句的值 强制转换成数值类型 if (count > 0) { session[ "name "] = textbox1.text; page.response.redirect( "webform2.aspx "); } else { response.write( " <script lanuage=javascript> alert( '用户名或密码有误! ');location= 'javascript:history.go(-1) ' </script> "); return; } } } } webform2.aspx: <%@ page language= "c# " codebehind= "webform2.aspx.cs " autoeventwireup= "false " inherits= "_1.webform2 " %> <!doctype html public "-//w3c//dtd html 4.0 transitional//en " > <html> <head> <title> webform2 </title> <meta name= "generator " content= "microsoft visual studio .net 7.1 "> <meta name= "code_language " content= "c# "> <meta name= "vs_defaultclientscript " content= "javascript "> <meta name= "vs_targetschema " content= "http://schemas.microsoft.com/intellisense/ie5 "> </head> <body ms_positioning= "gridlayout "> <form id= "form1 " method= "post " runat= "server "> <font face= "宋体 "> <asp:label id= "label1 " style= "z-index: 101; left: 200px; position: absolute; top: 128px " runat= "server " width= "256px " height= "80px "> </asp:label> </font> </form> </body> </html> webform2.aspx.cs: using system; using system.collections; using system.componentmodel; using system.data; using system.drawing; using system.web; using system.web.sessionstate; using system.web.ui; using system.web.ui.webcontrols; using system.web.ui.htmlcontrols; using system.data.sqlclient; namespace _1 { /// <summary> /// webform2 的摘要说明。 /// </summary> public class webform2 : system.web.ui.page { protected system.web.ui.webcontrols.label label1; private void page_load(object sender, system.eventargs e) { label1.text = session[ "name "].tostring(); } #region web 窗体设计器生成的代码 override protected void oninit(eventargs e) { // // codegen: 该调用是 asp.net web 窗体设计器所必需的。 // initializecomponent(); base.oninit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void initializecomponent() { this.load += new system.eventhandler(this.page_load); } #endregion } } |
|
|
|
|