c# - TextBox doesn't appear in code-behind even though I regenerated the designer.cs file -


i have little problem project. added textboxes .aspx file , can't see them in .aspx.designer.cs , hence can't use them in aspx.cs .

here .aspx file :

register.aspx:

<%@ page title="register" language="c#" masterpagefile="~/site.master" autoeventwireup="true"     codebehind="register.aspx.cs" inherits="learnef.account.register" %>  <asp:content id="headercontent" runat="server" contentplaceholderid="headcontent"> </asp:content>   <asp:content id="bodycontent" runat="server" contentplaceholderid="maincontent">     <asp:createuserwizard id="registeruser" runat="server" enableviewstate="false" oncreateduser="registeruser_createduser"> <%--        <layouttemplate>             <asp:placeholder id="wizardstepplaceholder" runat="server"></asp:placeholder>             <asp:placeholder id="navigationplaceholder" runat="server"></asp:placeholder>         </layouttemplate>--%>         <wizardsteps>             <asp:createuserwizardstep id="registeruserwizardstep" runat="server">                 <contenttemplate>                     <h2>                         create new account                     </h2>                     <p>                         use form below create new account.                     </p>                     <p>                         passwords required minimum of <%= membership.minrequiredpasswordlength %> characters in length.                     </p>                     <span class="failurenotification">                         <asp:literal id="errormessage" runat="server"></asp:literal>                     </span>                     <asp:validationsummary id="registeruservalidationsummary" runat="server" cssclass="failurenotification"                           validationgroup="registeruservalidationgroup"/>                     <div class="accountinfo">                         <fieldset class="register">                             <legend>account information</legend>                             <p>                                 <asp:label id="usernamelabel" runat="server" associatedcontrolid="username">user name:</asp:label>                                 <asp:textbox id="username" runat="server" cssclass="textentry" ontextchanged="username_textchanged"></asp:textbox>                                 <asp:requiredfieldvalidator id="usernamerequired" runat="server" controltovalidate="username"                                       cssclass="failurenotification" errormessage="user name required." tooltip="user name required."                                       validationgroup="registeruservalidationgroup">*</asp:requiredfieldvalidator>                             </p>                             <p>                                 <asp:label id="emaillabel" runat="server" associatedcontrolid="email">e-mail:</asp:label>                                 <asp:textbox id="email" runat="server" cssclass="textentry" ontextchanged="email_textchanged"></asp:textbox>                                 <asp:requiredfieldvalidator id="emailrequired" runat="server" controltovalidate="email"                                       cssclass="failurenotification" errormessage="e-mail required." tooltip="e-mail required."                                       validationgroup="registeruservalidationgroup">*</asp:requiredfieldvalidator>                             </p>                             <p>                                 <asp:label id="passwordlabel" runat="server" associatedcontrolid="password">password:</asp:label>                                 <asp:textbox id="password" runat="server" cssclass="passwordentry" textmode="password" ontextchanged="password_textchanged"></asp:textbox>                                 <asp:requiredfieldvalidator id="passwordrequired" runat="server" controltovalidate="password"                                       cssclass="failurenotification" errormessage="password required." tooltip="password required."                                       validationgroup="registeruservalidationgroup">*</asp:requiredfieldvalidator>                             </p>                             <p>                                 <asp:label id="confirmpasswordlabel" runat="server" associatedcontrolid="confirmpassword">confirm password:</asp:label>                                 <asp:textbox id="confirmpassword" runat="server" cssclass="passwordentry" textmode="password" ontextchanged="confirmpassword_textchanged"></asp:textbox>                                 <asp:requiredfieldvalidator controltovalidate="confirmpassword" cssclass="failurenotification" display="dynamic"                                       errormessage="confirm password required." id="confirmpasswordrequired" runat="server"                                       tooltip="confirm password required." validationgroup="registeruservalidationgroup">*</asp:requiredfieldvalidator>                                 <asp:comparevalidator id="passwordcompare" runat="server" controltocompare="password" controltovalidate="confirmpassword"                                       cssclass="failurenotification" display="dynamic" errormessage="the password , confirmation password must match."                                      validationgroup="registeruservalidationgroup">*</asp:comparevalidator>                             </p>                         </fieldset>                         <p class="submitbutton">                             <asp:button id="createuserbutton" runat="server" commandname="movenext" text="create user"                                   validationgroup="registeruservalidationgroup"/>                         </p>                     </div>                 </contenttemplate>                 <customnavigationtemplate>                 </customnavigationtemplate>             </asp:createuserwizardstep> <asp:completewizardstep runat="server"></asp:completewizardstep>         </wizardsteps>     </asp:createuserwizard> </asp:content> 

here register.aspx.cs : commented lines doesn't compile ...

register.aspx.cs :

using system; using system.collections.generic; using system.linq; using system.web; using system.web.security; using system.web.ui; using system.web.ui.webcontrols; using system.data; using system.configuration; using system.data.sqlclient;  namespace learnef.account {     public partial class register : system.web.ui.page     {          protected void registeruser_createduser(object sender, eventargs e)         {             int userid = 0;             string constr = configurationmanager.connectionstrings["applicationservices"].connectionstring;             using (sqlconnection con = new sqlconnection(constr))             {                 using (sqlcommand cmd = new sqlcommand("insert_user"))                 // note "insert_user" name of procedure                  // stored in `db_files` folder                  // when run piece of code , parameters @username , @password , @email                  // passed procedure                 {                     using (sqldataadapter sda = new sqldataadapter())                     {                         cmd.commandtype = commandtype.storedprocedure;                         cmd.parameters.addwithvalue("@username", username.text.trim());   // error  1   name 'username' not exist in current context                            cmd.parameters.addwithvalue("@password", password.text.trim());   // error  2   name 'password' not exist in current context                         cmd.parameters.addwithvalue("@email", email.text.trim());  // error 3   name 'email' not exist in current context                          cmd.connection = con;                         con.open();                         userid = convert.toint32(cmd.executescalar());                         con.close();                     }                 }                 string message = string.empty;                 switch (userid)                 {                     case -1:                         message = "username exists.\\nplease choose different username.";                         break;                     case -2:                         message = "supplied email address has been used.";                         break;                     default:                         message = "registration successful.\\nuser id: " + userid.tostring();                         break;                 }                 clientscript.registerstartupscript(gettype(), "alert", "alert('" + message + "');", true);             }         }          protected void confirmpassword_textchanged(object sender, eventargs e)         {          }          protected void email_textchanged(object sender, eventargs e)         {          }          protected void username_textchanged(object sender, eventargs e)         {          }          protected void password_textchanged(object sender, eventargs e)         {          } // end       }    } 

and here designer file :

register.aspx.designer.cs:

//------------------------------------------------------------------------------ // <auto-generated> //     code generated tool. // //     changes file may cause incorrect behavior , lost if //     code regenerated.  // </auto-generated> //------------------------------------------------------------------------------  namespace learnef.account {       public partial class register {          /// <summary>         /// registeruser control.         /// </summary>         /// <remarks>         /// auto-generated field.         /// modify move field declaration designer file code-behind file.         /// </remarks>         protected global::system.web.ui.webcontrols.createuserwizard registeruser;          /// <summary>         /// registeruserwizardstep control.         /// </summary>         /// <remarks>         /// auto-generated field.         /// modify move field declaration designer file code-behind file.         /// </remarks>         protected global::system.web.ui.webcontrols.createuserwizardstep registeruserwizardstep;     } } 

i deleted file register.aspx.designer.cs , hit convert web application got same register.aspx.designer.cs .

please me resolve .

thank

your textbox instances defined within template of server control; means child controls of server control , not member of page class, hence can't access directly.

to access them programmatically can use findcontrols method of appropriate control


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -