Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai friends
i am the new asp.net i am creating simple login page i faced one always
my concept is when a person make signup means if he ve dont any accounts means show message "WELCOME TO OUR PAGE" already exists the same means "ALREADY EXISTS" message.
show make the code here but showing error on "MESSAGE" showing The name "MESSAGE" does not exist in the current contex....... pls suggest some idea...



C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
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;

public partial class Regist : System.Web.UI.Page
{
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        if (txtpwd.Text == txtcnmpwd.Text)
        {
            string UserName = txtuser.Text;
            string Password = txtpwd.Text;
            string ConfirmPassword = txtcnmpwd.Text;
            string FirstName = txtfname.Text;
            string LastName = txtlname.Text;
            string Email = txtEmail.Text;
            string Phoneno = txtphone.Text;
            string Location = txtlocation.Text;
            string Created_By = txtuser.Text;
             
            SqlConnection con = new SqlConnection("Data Source=MYCBJ017550027;Initial Catalog=MySamplesDB;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("sp_userinformation", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@UserName", UserName);
            cmd.Parameters.AddWithValue("@Password", Password);
            cmd.Parameters.AddWithValue("@FirstName", FirstName);
            cmd.Parameters.AddWithValue("@LastName", LastName);
            cmd.Parameters.AddWithValue("@Email", Email);
            cmd.Parameters.AddWithValue("@PhoneNo", Phoneno);
            cmd.Parameters.AddWithValue("@Location", Location);
            cmd.Parameters.AddWithValue("@Created_By", Created_By);
            cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
            cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
            cmd.ExecuteNonQuery();
         message=(string) cmd.Parameters["@ERROR"].Value;
            con.Close();
        }
        else
        {
            Page.RegisterStartupScript("UserMsg", "<Script language='javascript'>alert('" + "Password mismatch" + "');</script>");
        }
        lblErrorMsg.Text = message; // SEE HERE
    }
}
Posted
Updated 17-Dec-12 0:04am
v2
Comments
Rai Pawan 17-Dec-12 6:08am    
You haven't even declared the message variable anywhere.

C#
string message=cmd.Parameters["@ERROR"].Value.ToString(); // declare type for message
lblErrorMsg.Text = message;  // now you can use it..
 
Share this answer
 
v4
You have not declared a type for message, but even if you did, it will only exist inside your if block. You need to declare it at the top of the event block like:
C#
protected void btnsubmit_Click(object sender, EventArgs e)
{
    string message = ""; // set default message text here
    if (txtpwd.Text == txtcnmpwd.Text)
    {
// ...
 
Share this answer
 
C#
protected void btnsubmit_Click(object sender, EventArgs e)
{
    string message = ""; //Default value. You can make it "" else string.empty

    if (txtpwd.Text == txtcnmpwd.Text)
    {
       message=cmd.Parameters["@ERROR"].Value.ToString();

      if(message!= null) // check here if message is returning some values.
      {
         lblErrorMsg.Text = message;
      }
    } // Missing } added
} // Missing } added


Hope this helps. :)

[edit]code block and missing "}" added[/edit]
 
Share this answer
 
v3
Comments
Jibesh 17-Dec-12 17:19pm    
it wont compile. will pops an error multiple declaration of message variable!! check string message is declared twice here
Member 9581488 17-Dec-12 20:20pm    
My mistake......declaration of message should take place only once.
thx.Edited my ans

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900