Wrox Programmer Forums
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2004, 03:31 AM
Registered User
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default code behind

Hi,everyone

I have login.aspx and login.aspx.cs.
When I click the button no event occurs.

Please help me!

login.aspx


<%@ Page Language="c#" src="login.aspx.cs" AutoEventWireup="false" Inherits="ciq.verify"%>
<html>
<head>
</head>
<body>
    <form runat="server" method=post>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <div align="center">
            <table bordercolor="#666666" width="200" align="center" bgcolor="#c0ffff" border="1">
                <tbody>
                    <tr>
                        <th colspan="2">
                            Login
                        </th>
                    </tr>
                    <tr>
                        <td>
                            Username:
                        </td>
                        <td>
                            <asp:TextBox id="userid" runat="server" MaxLength="10" Columns="10"></asp:TextBox>
                            <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" display="static" ControlToValidate="userid" ErrorMessage="*"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Password:
                        </td>
                        <td>
                            <asp:TextBox id="pwd" runat="server" Columns="10" MaxLength="8" TextMode="password"></asp:TextBox>
                            <asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" display="static" ControlToValidate="pwd" ErrorMessage="*"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th colspan="2">
                <asp:Button id="btnSubmit" runat="server" Text="Enter"></asp:Button>
                <asp:Label ID="errMessage" Runat=Server></asp:Label>
                        </th>
                    </tr>
                </tbody>
            </table>
        </div>
    </form>
</body>
</html>

login.aspx.cs


using System;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;



/// <summary>
/// Summary description for verify
/// </summary>
namespace ciq
{
    public class verify : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox userid;
    protected System.Web.UI.WebControls.TextBox pwd;
    protected System.Web.UI.WebControls.Button btnSubmit;
        protected System.Web.UI.WebControls.Label errMessage;

        private void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Page_Init(object sender,EventArgs e)
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
            this.Load += new System.EventHandler(this.Page_Load);
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            bool pwdVerified = false;
            try
            {
                //verify the password
                pwdVerified = verifyPwd(userid.Text, pwd.Text);
            }
            catch (Exception ex)
            {
                return;
            }

            //whether verified
            if (pwdVerified==true)
            {
                errMessage.Text = "ok!";
            }
            else
            {
                errMessage.Text = "Incorrect username or password!";
            }

        }

        private bool verifyPwd(string username, string pwd)
        {
            bool pwdMatch = false;
            //connect to database
            SqlConnection conn = new SqlConnection("server=(local);database=ciq;uid=sa, pwd=");
            string sSql="select pwd from user where userid='"+username+"'";
            SqlCommand cmd = new SqlCommand(sSql, conn);
            try
            {
                conn.Open();
                string sPwd = (string)cmd.ExecuteScalar();
                cmd.Dispose();
                conn.Dispose();
                pwdMatch=sPwd.Equals(pwd);
            }
            catch(Exception ex)
            {
            }
            return pwdMatch;
        }
    }
}

Any help will be greatly appreciated.
 
Old December 22nd, 2004, 06:06 AM
Authorized User
 
Join Date: Dec 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kk_katepally Send a message via Yahoo to kk_katepally
Default

i dont understand u mean . Let me clear one thing from u don't need password for opening the sqlserver connection.
SqlConnection conn = new SqlConnection("server=(local);database=ciq;uid=sa, pwd="----");
jus chek this out if u dont think itz not necessary then i'll let u know that..


kittu
 
Old December 22nd, 2004, 08:39 PM
Registered User
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.

I think the SQL connection is not necessary.The method verifyPwd() will return a boolean whether the connection is built.
My issue is when i click the button no message responds.

Can anyone help me.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.