C # .NET form submit cannot get new / changed values ​​for form elements

I am creating an ASP.NET page in C # to add / modify details and then save this data in a MySQL database. To do this, I created the main page "Main.Master" in the form of web content "modify.aspx" and its code. The code for "Main.Master" is given below. The wizard contains a 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>

The code for "modify.aspx" is below. This page contains only form elements.

<%@ 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>

When the "Submitowner" button is clicked, "modify.aspx" is sent to the "modifyDetails" controller method, which is present in the "modify.aspx.cs" code behind the file. The "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();
    }

. , - "ownfname", "Robert", "", "". "ownfname.Text" - "", "". , .

, . ? - /? .

+3
1

,

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

, .

ASP.net , . , asp.net.

+2

All Articles