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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:46:29+00:00 2026-05-21T22:46:29+00:00

I am creating a ASP.NET page in C# to add/modify details and then save

  • 0

I am creating a ASP.NET page in C# to add/modify details and then save those details in MySQL database. For this I have created a master page “Main.Master” a web content form “modify.aspx” and its code behind.
Code for “Main.Master” is as given below. Master contains form tag declaration.

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Main.master.cs" Inherits="WebApplication.Main" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="mainmasterform" method="post" runat="server">
        <div id="container">
            <div id="maincontent">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                </asp:ContentPlaceHolder>
            </div>
        </div>
    </form>
</body>
</html>

Code for “modify.aspx” is as given below. Only form elements are present in this page.

<%@ Page Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="modify.aspx.cs" Inherits="WebApplication.modify" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table align="center">
    <tr>
        <td><label for="ownfname">First Name</label></td>
        <td><asp:TextBox id="ownfname" runat="server" TextMode="SingleLine"/></td>
    </tr>
    <tr>
        <td><label for="ownlname">Last Name</label></td>
        <td><asp:TextBox id="ownlname" runat="server" TextMode="SingleLine"/></td>
    </tr>
    <tr>
        <td colspan="2">
            <asp:Button ID="submitowner" runat="server" Text="Submit" onclick="modifyDetails" />
        </td>
    </tr>
</table>
</asp:Content>

On click of “submitowner” button submits “modify.aspx” to a controller method “modifyDetails” present in “modify.aspx.cs” code behind file. “modifyDetails” code is as follows.

protected void modifyDetails(object sender, EventArgs e) {
        string cmdstr = "UPDATE owners SET first_name=?, last_name=? WHERE userid=?";
        OdbcConnection odbccon = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQL55"].ConnectionString);
        OdbcCommand odbccmd = new OdbcCommand(cmdstr, odbccon);
        string fname = ownfname.Text;
        string lname = ownlname.Text;
        odbccmd.Parameters.Add("@fname", OdbcType.NVarChar, 50).Value = fname;
        odbccmd.Parameters.Add("@lname", OdbcType.NVarChar, 50).Value = lname;
        odbccmd.Parameters.Add("@userid", OdbcType.Int).Value = userid;
        odbccon.Open();
        odbccmd.ExecuteScalar();
    }

Now I am facing trouble in getting new values of form elements. As for example when the web page is rendered text within “ownfname” is “Robert” and then you modify it to “David” then click on submit button. After submitting accessing the “ownfname.Text” property still gives “Robert” and not “David”. I tried searching for a solution but no luck.

I am not able to understand what is the exact problem here.
Is the code wrong? Can anyone help me figure out the issue/problem ?
I apologize for such a long question.

  • 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-05-21T22:46:29+00:00Added an answer on May 21, 2026 at 10:46 pm

    If you are loading the initial values into your form fields on page load you need to use

    protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
         {
            //Populate form fields
         }
    }
    

    This will ensure that the fields are not overwritten on post back.

    If you’re not overly familiar with the ASP.net page life cycle this article is well worth the read. It explains the order of events when an asp.net page is loaded.

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

Sidebar

Related Questions

I have one asp.net page. I want to add this page to asp.net mvc
Am creating a script using JQuery on an ASP.NET page. Have a JSON string
I have a document that my asp.net page is creating and I need to
i have a small problem, i am creating a edit page in my asp.net
I have a ASP.NET Application that add data to a DataBase and get data
I have created a asp.net Dynamic data linq to sql web site. After creating
I'm creating an asp.net page that uses the google map api. The page loads
I am creating an ASP.NET page where I need a couple of variables which
I am creating web page using asp.net. Is it possible to remove/hide the browsers
I am creating a diagnostic page for ASP.NET and would like to programatically detect

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.