Click here to Skip to main content
11,712,126 members (77,598 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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...



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 17-Dec-12 0:01am
Edited 17-Dec-12 0:04am
v2
Comments
Rai Pawan at 17-Dec-12 6:08am
   
You haven't even declared the message variable anywhere.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

string message=cmd.Parameters["@ERROR"].Value.ToString(); // declare type for message
lblErrorMsg.Text = message;  // now you can use it..
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
protected void btnsubmit_Click(object sender, EventArgs e)
{
    string message = ""; // set default message text here
    if (txtpwd.Text == txtcnmpwd.Text)
    {
// ...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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. Smile | :)

[edit]code block and missing "}" added[/edit]
  Permalink  
v3
Comments
jibesh at 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 at 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)

  Print Answers RSS
0 CHill60 335
1 Sergey Alexandrovich Kryukov 254
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130
0 CHill60 335
1 Sergey Alexandrovich Kryukov 245
2 OriginalGriff 230
3 Andy Lanng 160
4 Maciej Los 130


Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100