You must Sign In to post a response.
  • Category: .NET

    How to show textbox to visible while sending datafrom one page to anotherusing application

    hai all i have two pages like
    hr.aspx and empdetails.aspx


    so in hr .aspx some textboxes are there
    eid,ename,esal,eage,eaddress
    for eaddress i have 4textboxes ie if the employee changes address for that i have given
    so what i want is if employee has not changed any addres when click on button so in empdetails i have given four textboxes for eaddress so if it has one address one textbox to be visisble
    esle if the employee has 3 addresss 3 textbox to be opened
    below is my code
    so where iam wrong helpme
    in
    Hr.aspx.cs

    protected void Button1_Click(object sender, EventArgs e)
    {

    Application["ename"] = TextBox2.Text;
    Application["eaddress"] = TextBox3.Text;
    Application["eaddressa"] = TextBox8.Text;
    Application["eaddressb"] = TextBox9.Text;
    Application["epanno"] = TextBox4.Text;
    Application["password"] = TextBox5.Text;
    Application["chpassword"] = TextBox6.Text;
    Application["email"] = TextBox7.Text;
    Application["pc"] = Image2.ImageUrl;

    Response.Redirect("emp details.aspx");
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection(connStr);
    SqlCommand cmd = new SqlCommand("select eaddress from ekthaemployee where eid ='" + TextBox1.Text + "'", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds, "ekthaemployee");
    if (ds.Tables["ekthaemployee"].Rows.Count > 0)
    {


    TextBox3.Text = ds.Tables["ekthaemployee"].Rows[0][0].ToString();
    TextBox3.Visible = true;
    }
    if (ds.Tables["ekthaemployee"].Rows.Count > 1)
    {



    TextBox8.Text = ds.Tables["ekthaemployee"].Rows[1][0].ToString();
    TextBox8.Visible = true;
    }
    if (ds.Tables["ekthaemployee"].Rows.Count > 2)
    {



    TextBox9.Text = ds.Tables["ekthaemployee"].Rows[2][0].ToString();
    TextBox9.Visible = true;
    }
    con.Open();
    cmd.ExecuteNonQuery();
    con.Close();

    }

    so in empdetails.aspx

    public partial class emp_details : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {



    TextBox1.Text = Application["ename"].ToString();
    TextBox2.Text = Application["eaddress"].ToString();
    if (Application["eaddressa"] == null)
    {
    //TextBox7.Text = Application["eaddressa"].ToString();
    TextBox7.Visible = false;
    }
    else
    if (Application["eaddressa"] != null)
    {
    TextBox7.Text = Application["eaddressa"].ToString();
    TextBox7.Visible = true;
    }
    if (Application["eaddressb"] == null)
    {
    TextBox8.Text = Application["eaddressb"].ToString();
    TextBox8.Visible = false;
    }
    else
    if (Application["eaddressb"] != null)
    {
    TextBox8.Text = Application["eaddressb"].ToString();
    TextBox8.Visible = true;
    }

    TextBox3.Text = Application["epanno"].ToString();
    TextBox4.Text = Application["password"].ToString();
    TextBox5.Text = Application["chpassword"].ToString();
    TextBox6.Text = Application["email"].ToString();
    Image1.ImageUrl = Application["pc"].ToString();



    }
  • #763894
    Some tips.

    1. Why you are using "Application" object. Why cant you go for Session?


    2. you are checking all the objects
    if (Application["eaddressa"] != null)

    You are assigning text box value in the button click right?. So the value will be blank("") it is not null. So you can try to check blank also

    if ((Application["eaddressa"]+"").toString() != "")

    By Nathan
    Direction is important than speed

  • #763901
    Hi,

    The best solution to resolve this is debug the code and check the result for every action.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763911
    Hai VELIDIRAVIRAM,
    The first problem is the use of Application object. The application object should be used only when you need to keep the application related data.
    So instead you can use the query string to keep this data when moving from first page to second page. You can get all the data in to next page and based on this data, you can generate the text-boxes.
    So your button click event should have:

    protected void Button1_Click(object sender, EventArgs e)
    {
    var ename = TextBox2.Text;
    var eaddress = TextBox3.Text;
    var eaddressa = TextBox8.Text;
    var eaddressb = TextBox9.Text;
    var epanno = TextBox4.Text;
    var password = TextBox5.Text;
    var chpassword = TextBox6.Text;
    var email = TextBox7.Text;
    var pc = Image2.ImageUrl;
    Response.Redirect("empdetails.aspx?name='"+ename+"'&address='"+eaddress&+"'&...");
    }

    Now you need to get this data in to the next page by using Request.QueryStrings["name"] for each values.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764087
    Hi VELIDIRAVIRAM,

    Just replace the Page_Load() event from empdetails.aspx with following:

    protected void Page_Load(object sender, EventArgs e)
    {
    TextBox1.Text = Application["ename"].ToString();
    TextBox2.Text = Application["eaddress"].ToString();

    if (Application["eaddressa"] != null && Application["eaddressa"].ToString() != "")
    {
    TextBox7.Text = Application["eaddressa"].ToString();
    TextBox7.Visible = true;
    }
    else
    {
    TextBox7.Visible = false;
    }
    if (Application["eaddressb"] != null Application["eaddressb"].ToString() != "")
    {
    TextBox8.Text = Application["eaddressb"].ToString();
    TextBox8.Visible = true;
    }
    else
    {
    TextBox8.Visible = false;
    }

    TextBox3.Text = Application["epanno"].ToString();
    TextBox4.Text = Application["password"].ToString();
    TextBox5.Text = Application["chpassword"].ToString();
    TextBox6.Text = Application["email"].ToString();
    Image1.ImageUrl = Application["pc"].ToString();
    }

    Hope this will help you.

    Regards,
    Shashikant Gurav[Programmer II]
    shashikantgurav22@gmail.com


Sign In to post your comments