1

I have a bootstrap register page when i want to use bootstrap control's property in c# get this Error The name 'control id' does not exist in the current context

register.aspx

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="register.aspx.cs" Inherits="_3layer_cms.register" %>

<link href="css/bootstrap.css" rel="stylesheet" />
<script src="Scripts/jquery-1.11.3.js"></script>
<script src="js/bootstrap.min.js"></script>

<html lang="en">
<link href="css/bootstrap.css" rel="stylesheet" />
<script src="Scripts/jquery-1.11.3.js"></script>
<script src="js/bootstrap.min.js"></script>
     <head id="Head1" runat="server">
       <title>Registration Form</title>
     <style type="text/css">
    body{
    background-color: #525252;
}
.centered-form{
  margin-top: 190px;
}

.centered-form .panel{
  background: rgba(255, 255, 255, 0.8);
  box-shadow: rgba(0, 0, 0, 0.3) 20px 20px 20px;
}
     </style>
   </head>
   <body>
           <div class="container">
        <div class="row centered-form">
        <div class="col-xs-12 col-sm-8 col-md-4 col-sm-offset-2 col-md-offset-4">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title"></h3>
             </div>
             <div class="panel-body">
              <form role="form">
                <div class="row">
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    <asp:Content ID="Content2" ContentPlaceHolderID="ContentSection" runat="server">
                    <div class="form-group">
                      <input type="text" name="name" id="txtname" class="form-control input-sm" role="textbox" placeholder="name:">
                    </div>
                    </asp:Content>
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    <div class="form-group">
                      <input type="password" name="password" id="txpass" class="form-control input-sm" placeholder="password:">
                    </div>
                  </div>
                </div>

                <div class="form-group">
                  <input type="text" name="city" id="txAddress" class="form-control input-sm" placeholder="address:">
                </div>

                <div class="row">
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    <div class="form-group">
                      <input type="email" name="email" id="txtEmailID" class="form-control input-sm" placeholder="email:">
                    </div>
                  </div>
                  <div class="col-xs-6 col-sm-6 col-md-6">
                    <div class="form-group">
                      <input type="number" name="number" id="txtmobile" class="form-control input-sm" placeholder="phone :">
                    </div>
                  </div>
                </div>

                <input type="submit"  id="BtnSave" onclick="BtnSave_Click()" value="ثبت نام" class="btn btn-primary btn-block">

              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
          </body>
</html>

my c# code:

register.aspx.cs

protected void BtnSave_Click(object sender, EventArgs e)
        {
            if (txtname.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Please Enter Name')", true);
            }

            else  if (txpass.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Please Enter Password')", true);
            }
            else if (txAddress.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Please Enter City')", true);
            }
            else if (txtEmailid.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Please Enter EmailID')", true);
            }
            else if (txtmobile.Text == "")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Please Enter Mobile no')", true);
            }
            else
            {
                UserBO ObjUBO = new UserBO();
                /*
                 calling BussinessObject (UserBO) 
                 And passing all value from Control to it.
                */
                UserBL objUBL = new UserBL();

                ObjUBO.Name = txtname.Text;
                ObjUBO.address = txAddress.Text;
                ObjUBO.EmailID = txtEmailid.Text;
                ObjUBO.Mobilenumber = txtmobile.Text;
                string hashedPass = objUBL.getMd5Hash(txpass.Text);
                ObjUBO.Pass = hashedPass;


                int result = objUBL.SaveUserregisrationBL(ObjUBO);

                if (result > 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('suceesfully regist :-)')", true);
                }

                /*
                 Calling Bussinesslogic (UserBL) 
                 And Passing Value To it  
                */
            }
        }

error list:

my error list

I thought my problem is connecting aspx and c# but it's It was wrong

my tested solution

thanks in advance

mohammad
  • 13
  • 4

1 Answers1

0

Somehow you have copy/paste some code and you have mix page that must have some master page reference but did not have it.

There are two points.

You have the asp:Content that to work you need to reference some master page

 <asp:Content ID="Content2" ContentPlaceHolderID="ContentSection" runat="server">

but the code on that case must not be like that, you are not allow to have html code out side the asp:Content... so probably if you remove all asp:Content will work.

Other bugs

From the other hand the page include <form> not in the way asp.net need to be.

You have mix a page and now if full of bugs...

Start with a new page, make it from visual studio and start build it - not copy/paste some other code that way... there will not work that way... and maybe you need to learn asp.net to understand what the form must be, how its work and all that, later to go to some complicate page like this one.

The form tag must be something like

<form id="form1" runat="server" >

to make your page see the inside controls.

Aristos
  • 66,005
  • 16
  • 114
  • 150