Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to add an update query in my Gridview.aspx.cs file but its show error that text boxes is not exist in current context
if i add Grid view and my registration page in same page than i can access my Textboxes ID but i want to add grid view in another page so that user can add data in one page and its redirect to my gridview
Hope you got me

C#
try
        {
            SqlConnection conn = new SqlConnection("Data Source=DESKTOP-KNR6L52;Initial Catalog=FarhanDB;Integrated Security=True");
            conn.Open();
            string insertQuery = "Insert into AddRecord (InternalRecieving,Department,DepartmentType,Orignization,OrignizationType,FileNumber,Date,Subject,FileName,Status)Values(@Fname,@lname,@CNIC,@Gnder,@Mb1,@Mb2,@datebirth,@EmailId,@WD,@Pkge)";

            SqlCommand com = new SqlCommand(insertQuery, conn);
            com.Parameters.AddWithValue("@Fname", InternalRecievingbox.Text);
            com.Parameters.AddWithValue("@lname", Departmentbox.Text);
            com.Parameters.AddWithValue("@CNIC", DpartmnttypeID.Text);
            com.Parameters.AddWithValue("@Gnder", orignizationbox.Text);
            com.Parameters.AddWithValue("@Mb1", orignizationtypebox.Text);
            com.Parameters.AddWithValue("@Mb2", filenumbox.Text);
            com.Parameters.AddWithValue("@datebirth", datebox.Text);
            com.Parameters.AddWithValue("@EmailId", subjctbox.Text);
            com.Parameters.AddWithValue("@WD", filanmebox.Text);
            com.Parameters.AddWithValue("@Pkge", ststbox.Text);
            com.ExecuteNonQuery();
            Response.Write("alert('Your Regestration is Successfull')");
            Response.Redirect("Showtable.aspx");
            //REfershData();
            //Clear();

            conn.Close();
        }
        catch (Exception ex)
        {
            Response.Write("Error." + ex.ToString());


        }


What I have tried:

I have tried only one thing that is "add Grid view and my registration page in same page than i can access my Textboxes but i want to redirect it on gridview page as i mentioned above"
Here is my code
Posted
Updated 31-Jan-17 22:44pm
v4

1 solution

When your second page is executing, the first page is gone. The TextBox that you are trying to access will simply no longer exists. That's the nature of the web - stateless.

However, there are a few possible solutions for that scenario, and that is to use CrossPagePostBack with Server.Transfer method or setting the PostBackUrl of a Button server control. Take a look at this for example: Find (Access) control from one page to another in ASP.Net using C# and VB.Net[^]

Another way that I would recommend is to expose a public properties for controls that you want to access from other pages. This properties will hold the control values.
 
Share this answer
 

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