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 8520319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:30:04+00:00 2026-06-11T06:30:04+00:00

I got a question. When I put this code protected void Page_Load(object sender, EventArgs

  • 0

I got a question. When I put this code

protected void Page_Load(object sender, EventArgs e)
{
    string email = Membership.GetUser(User.Identity.Name).Email;
    MembershipUser currentUser = Membership.GetUser();
    string UserId = currentUser.ProviderUserKey.ToString();

    **TextBox2.Text = email;
    TextBox3.Text = UserId;**
}

My data will not be saved to the database.

 {
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
    SqlCommand cmd = new SqlCommand("UPDATE aspnet_Membership SET Email = @email WHERE UserId = @id1", conn);

    cmd.Connection = conn;
    cmd.CommandType = CommandType.Text;
    cmd.Parameters.AddWithValue("@email", TextBox2.Text);
    cmd.Parameters.AddWithValue("@id1", TextBox3.Text);
    try
    {
        conn.Open();
        cmd.ExecuteNonQuery();

    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        conn.Close();
    }

But when I removed

 **TextBox2.Text = email;
TextBox3.Text = UserId;**

The data will be saved into database using above code. Can someone tell me why? Thanks in advance.

  • 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-11T06:30:06+00:00Added an answer on June 11, 2026 at 6:30 am

    Given you never execute the command I can’t explain it.

    Add

    cmd.ExecuteNonQuery();
    

    To the end of your click method

    Because you are setting the values in your page load event, they are overwriting the changed values in the controls when your button on postback. Wrap your page load code with a

    if (!Page.IsPostback)
    {
        string email = Membership.GetUser(User.Identity.Name).Email; 
        MembershipUser currentUser = Membership.GetUser(); 
        string UserId = currentUser.ProviderUserKey.ToString(); 
    
        TextBox2.Text = email; 
        TextBox3.Text = UserId; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question got me thinking about bare strings. When PHP sees a string that's
I got a little question about databases and android. I got this code: sampleDB
Got a question for some jQuery wizard who might stumble upon this. When I
EDIT : I've re-written this question, as I got no answer and I'm currently
First, I don't know if this is the correct place to put this question.
I've posted variations of this question before and just as I think I've got
Disclaimer: I have looked through this question and this question but they both got
So let's say I've got this code <a href=www.yourdomain.com><img src=http://www.image.com/image.jpg /></a> Super simple code.
I got this question at an interview and at the end was told there
EDIT: This got way too complicated, I will migrate this question to another question

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.