Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:30:41+00:00 2026-06-12T02:30:41+00:00

I have 2 pages, page 1 include the gridview and I made one linkbutton

  • 0

I have 2 pages, page 1 include the gridview and I made one linkbutton that passes the ID to another page ( page 2). On page 2 I fill 10 textboxes and I have one button for edit info.

This code is for page 1 :

...
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="lbNextPage" runat="server" 
                    PostBackUrl='<%# "~/secure/upst.aspx?id="+ Eval("ID_st") %>'>edit</asp:LinkButton>
                &nbsp;
            </ItemTemplate>
        </asp:TemplateField>

…

and this is the code for page 2:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        txtID.Text = Request.QueryString["id"].ToString();
    }
    SqlConnection con = new SqlConnection(strcon);
    string query = "select * from user_st where ID_st = @id";
    SqlCommand cmd = new SqlCommand(query, con);
        cmd.Parameters.AddWithValue("@id", stid);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();

        txtName.Text = dr["name"].ToString();
        txtFamily.Text = dr["family"].ToString();
        txtAddress.Text = dr["adres"].ToString();
        txtHomeTel.Text = dr["home_tel"].ToString();
        txtTahsilat.Text = dr["tahsilat"].ToString();
        txtTel.Text = dr["celphone"].ToString();
        txtEmail.Text = dr["email"].ToString();
        txtShoghl.Text = dr["shoghl"].ToString();
        txtAge.Text = dr["age"].ToString();
        txtFadername.Text = dr["fader_name"].ToString();
        txtIDnumber.Text = dr["melli_code"].ToString();
        txtShSh.Text = dr["sh_sh"].ToString();

} 

protected void btnOk_Click(object sender, EventArgs e)
{


    Boolean res = false;
    SqlConnection conn = new SqlConnection(strcon);

    string famil = txtFamily.Text;
    string name = txtName.Text;
    string fader = txtFadername.Text;
    string tahsil = txtTahsilat.Text;
    Double telhome = Convert.ToDouble(txtHomeTel.Text);
    string adres = txtAddress.Text;
    Double cel = Convert.ToDouble(txtTel.Text);
    string email = txtEmail.Text;
    Double shsh = Convert.ToDouble(txtIDnumber.Text);
    string shoghl = txtShoghl.Text;
    int age = Convert.ToInt32(txtAge.Text);
    Double melli = Convert.ToDouble(txtIDnumber.Text);
    int id = Convert.ToInt32(txtID.Text);


    string query = "update user_st set name=@name ,fader_name=@fader ,family=@famil,tahsilat=@tahsil,adres=@adres,home_tel=@telhome,celphone=@cel,email=@email ,sh_sh=@shsh,shoghl=@shoghl,age=@age,melli_code=@melli where ID_st=@id";

    SqlCommand cmdup = new SqlCommand(query, conn);
    cmdup.Parameters.AddWithValue("@name",name);
    cmdup.Parameters.AddWithValue("@fader_name",fader );
    cmdup.Parameters.AddWithValue("@family", famil);
    cmdup.Parameters.AddWithValue("@tahsilat",tahsil);
    cmdup.Parameters.AddWithValue("@adres", adres);
    cmdup.Parameters.AddWithValue("home_tel",telhome );
    cmdup.Parameters.AddWithValue("@celphone",cel );
    cmdup.Parameters.AddWithValue("@email", email);
    cmdup.Parameters.AddWithValue("@sh_sh", shsh);
    cmdup.Parameters.AddWithValue("@shoghl", shoghl);
    cmdup.Parameters.AddWithValue("@age",age );
    cmdup.Parameters.AddWithValue("@melli_code", melli);
    cmdup.Parameters.AddWithValue("@id", id);


    try
    {
        conn.Open();
        cmdup.ExecuteNonQuery();
        conn.Close();
        res = true;
    }
    catch (SqlException ex)
    {
        lblRes.Text = "error" + ex.ToString();
    }

    if (res)
    {
        lblResult.Text = "Ok";
    }

That is not working so, I tried this:

        //cmdup.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = txtName.Text;
    //cmdup.Parameters.Add("@fader_name", SqlDbType.NVarChar, 50).Value = txtFadername.Text;
    //cmdup.Parameters.Add("@family", SqlDbType.NVarChar, 50).Value = txtFamily.Text;
    //cmdup.Parameters.Add("@tahsilat", SqlDbType.NVarChar, 50).Value = txtTahsilat.Text;
    //cmdup.Parameters.Add("@adres", SqlDbType.NVarChar, 150).Value = txtAddress.Text;
    //cmdup.Parameters.Add("home_tel", SqlDbType.Char, 10).Value = txtHomeTel.Text;
    //cmdup.Parameters.Add("@celphone", SqlDbType.Char, 10).Value = txtTel.Text;
    //cmdup.Parameters.Add("@email", SqlDbType.VarChar).Value = txtEmail.Text;
    //cmdup.Parameters.Add("@sh_sh", SqlDbType.Char, 10).Value = txtShSh.Text;
    //cmdup.Parameters.Add("@shoghl", SqlDbType.NVarChar, 50).Value = txtShoghl.Text;
    //cmdup.Parameters.Add("@age", SqlDbType.Int).Value = txtAge.Text;
    //cmdup.Parameters.Add("@melli_code", SqlDbType.Char, 10).Value = txtIDnumber.Text;
    //cmdup.Parameters.Add("@id", SqlDbType.Int).Value = txtID.Text;

or this :

        //SqlCommand cmdup = new SqlCommand("EXEC up_st'" + txtName.Text. + "' , '" + txtFamily.Text + "' , '" + txtTahsilat.Text +"' , '" + txtAddress.Text + "' , '" 
    //                                   + txtHomeTel.Text + "' , '" + txtTel.Text + "' , '" + txtEmail.Text + "' , '" + txtShoghl.Text + "' , '"
    //                                   + txtAge.Text + "' , '" + txtFadername.Text + "' , '" + txtIDnumber.Text + "' , '" + txtShSh.Text + "' , '" 
    //                                   + txtID.Text + "'", conn);

or this :

        /*"update user_st set name='" + txtName.Text + "',fader_name='" + txtFadername.Text + "',family='" + txtFamily.Text + "',tahsilat='" + txtTahsilat.Text + "',adres='" + txtAddress.Text + "',home_tel='" + txtHomeTel.Text + "',celphone='" 
        + txtTel.Text + "',email='" + txtEmail.Text + "',sh_sh='" +                      txtShSh.Text + "',shoghl='" + txtShoghl.Text + "',age='" + txtAge.Text + "',melli_code='" + txtIDnumber.Text + "' where ID_st=" + txtID.Text*/

but it also doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:30:43+00:00Added an answer on June 12, 2026 at 2:30 am

    You need to move your initial Sql select into the !IsPostback block because what’s happening is you are posting back your updates, but Page_Load fires before the textboxes are updated. So everything is working in your initial code, you are just updating it with the initial information. Try this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtID.Text = Request.QueryString["id"].ToString();
            SqlConnection con = new SqlConnection(strcon);
            string query = "select * from user_st where ID_st = @id";
            SqlCommand cmd = new SqlCommand(query, con);
            cmd.Parameters.AddWithValue("@id", stid);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Read();
    
            txtName.Text = dr["name"].ToString();
            txtFamily.Text = dr["family"].ToString();
            txtAddress.Text = dr["adres"].ToString();
            txtHomeTel.Text = dr["home_tel"].ToString();
            txtTahsilat.Text = dr["tahsilat"].ToString();
            txtTel.Text = dr["celphone"].ToString();
            txtEmail.Text = dr["email"].ToString();
            txtShoghl.Text = dr["shoghl"].ToString();
            txtAge.Text = dr["age"].ToString();
            txtFadername.Text = dr["fader_name"].ToString();
            txtIDnumber.Text = dr["melli_code"].ToString();
            txtShSh.Text = dr["sh_sh"].ToString();
        }
    } 
    

    If you really want to reload the stuff from the database, you can pop that query into a function and re-run it after the button click update in the button click function (at the end), but there really is no reason since the textboxes will already have the same info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that uses another page via the include() function. The page
I have two pages one is the main page and the another one is
I have a page that includes a GridView in it. That GridView is paged
I have a JSF page that is included in other JSF pages (basically a
I have a index.php page that is the main page. All pages are included
I have several pages and one stylesheet. The page bodies get two classes: Their
I have a aspx page that has a GridView with a datasource of an
Is it possible to make one master page simply include another master page? I
I have listing pages that take a page argument on the url like the
I have 3 pages in my set up here: login.php: The login page that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.