web文件的aspx.cs中的bootstrap控件找不到asp app

时间:2016-07-14 08:47:50

标签: asp.net twitter-bootstrap webforms

当我想在c#中使用bootstrap控件的属性时,我有一个bootstrap寄存器页面得到此错误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>

我的c#代码:

  

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  
                */
            }
        }
  

错误列表:

my error list

我认为我的问题是连接aspx和c#,但这是错误的

my tested solution

提前致谢

1 个答案:

答案 0 :(得分:0)

不知何故,你有复制/粘贴一些代码,你有混合页面,必须有一些主页参考,但没有它。

有两点。

您需要asp:Content才能参考某个母版页

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

但该案例中的代码不能是这样的,您不允许在asp:Content旁边放置html代码...所以如果删除所有asp:Content可能会有效。

其他错误

另一方面,页面包含<form>,而不是asp.net需要的方式。

你混合了一个页面,现在如果充满了bug ......

从一个新页面开始,从visual studio开始构建它 - 不要复制/粘贴其他一些代码......不会那样工作......也许你需要学习asp.net到理解表格必须是什么,它的工作方式以及所有这些,以后再去一些像这样复杂的页面。

表单标记必须类似

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

让您的页面看到内部控件。