Click here to Skip to main content
15,914,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have three textboxes. Textbox1 user can enter email address. This is also where my TextChange is at. Textbox2 and Textbox3 is what I want to display when TextBox1 changes. So, when a user enter their email address into TextBox1, TextBox 2 should display UserID and TextBox3 should display Level. I do have the TextBox1 AutoPostBack set to true. Please help!! What did I do wrong?

C#
protected void TextBoxEA_TextChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con2.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, accessLevel from TableCEO where EmailAddress = '" + TextBoxEA.Text + "'", con);
        SqlCommand scmd2 = new SqlCommand("Select INST_ID, accessLevel from TableIALO where EmailAddress = '" + TextBoxEA.Text + "'", con2);
        SqlDataReader dr = scmd.ExecuteReader();
        SqlDataReader dr2 = scmd2.ExecuteReader();

        if (dr.Read())
        if (dr2.Read())
            {
                TextBoxINST_ID.Text = dr["INST_ID"].ToString();
                TextBoxaccessLevel.Text = dr["accessLevel"].ToString();
                TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
                TextBoxaccessLevel.Text = dr2["accessLevel"].ToString();
            }
        dr.Close();
        con.Close();
        dr2.Close();
        con2.Close();
    }
   
}


Here is an Updated code. I forgot somethings and it still will not work. What did I do wrong?
Posted
Updated 29-Oct-13 8:25am
v2

Set true for TextBoxEA's AutoPostBack property
 
Share this answer
 
Comments
Computer Wiz99 29-Oct-13 14:42pm    
thatraja, it is set to true. What else could be wrong?
thatraja 29-Oct-13 14:54pm    
Did you get values on other textboxes(TextBoxINST_ID, TextBoxaccessLevel) while debugging? Did the breakpoint enter into if conditions?
Ok This is not a Solution. I found out why it didn't work. I had to rename a field in my table. Once I did that now I get the other thing going on. When a user enters in an EmailAddress into TextBoxEA, the error massage that I made pops up: "User Name Already Exist!!!". Here is the code for the whole form:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Security.Cryptography;

public partial class SubmitPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
            con.Open();
            string cmdStr = "Select count(*) from TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
            SqlCommand userExist = new SqlCommand(cmdStr, con);
            SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from TableSecurity", con);
            int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
            if (temp == 0)
            {
                lblMessage.Text = "User Name Already Exist!!!";
            }
        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        string cmdStr = "Select INST_ID, accessLevel, EmailAddress from TableCEO where EmailAddress='" + TextBoxEA.Text + "'";
        string cmdStr2 = "Select INST_ID, accessLevel, EmailAddress from TableIALO where EmailAddress='" + TextBoxEA.Text + "'";
        string insCmd = "Insert into TableSecurity (EmailAddress, Password, INST_ID, accessLevel) values (@EmailAddress, @Password, @INST_ID, @accessLevel)";
        string insCmd2 = "Insert into TableSecurity (EmailAddress, Password, INST_ID, accessLevel) values (@EmailAddress, @Password, @INST_ID, @accessLevel)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        SqlCommand insertUser2 = new SqlCommand(insCmd2, con);
        insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
        insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
        insertUser.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        insertUser.Parameters.AddWithValue("@accessLevel", TextBoxaccessLevel.Text);
        
        try
        {
            insertUser.ExecuteNonQuery();
            con.Close();
            Response.Redirect("Login.aspx");
        }
        catch (Exception er)
        {
            lblMessage.Text = "User Already Exist";
        }
        finally
        {
        }
    }

    protected void TextBoxEA_TextChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con2.Open();

        SqlCommand scmd = new SqlCommand("Select INST_ID, accessLevel from TableCEO where EmailAddress = '" + TextBoxEA.Text + "'", con);
        SqlCommand scmd2 = new SqlCommand("Select INST_ID, accessLevel from TableIALO where EmailAddress = '" + TextBoxEA.Text + "'", con2);
        SqlDataReader dr = scmd.ExecuteReader();
        SqlDataReader dr2 = scmd2.ExecuteReader();

        if (dr.Read())
        if (dr2.Read())
            {
                TextBoxINST_ID.Text = dr["INST_ID"].ToString();
                TextBoxaccessLevel.Text = dr["accessLevel"].ToString();
                TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
                TextBoxaccessLevel.Text = dr2["accessLevel"].ToString();
            }
        dr.Close();
        con.Close();
        dr2.Close();
        con2.Close();
    }
   
}
 
Share this answer
 
v2

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