Asp Button单击事件未在表单runat中触发

时间:2014-05-09 00:02:57

标签: asp.net button master-pages runat

我真的很困惑,我花了很多时间寻找解决方案而且没有让我满意。

问题是我有一个包含表格runat =" server"以及一个名为" GestionUtilisateurs"。

的母版页面

当我打开" GestionUtilisateurs"页面所有asp按钮事件在我点击时没有触发(没有任何反应,没有例外...)。 我试图解决这个问题,所以我删除了表单runat =" server"位于主页和按钮事件返回工作。问题是我无法从母版页中删除表单,因为我需要将asp控件放在该表单中。当然,我不能为另一个页面添加特定的表单,因为它将是2 runat =" server"页面执行时在同一页面中形成...

这是GestionUtilisateur.aspx:

  <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="GestionUtilisateurs.aspx.cs" Inherits="administration.GestionUtilisateurs" %>
<asp:Content ID="GestionUtilisateurs" ContentPlaceHolderID="contenu" runat="server">
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1>Gestion des utilisateurs</h1>
                <ol class="breadcrumb">
                    <li><i class="fa fa-dashboard"></i>Accueil</li>
                    <li class="active"><i class="fa fa-users"></i>Gestion des utilisateurs</li>
                </ol>
            </div>
        </div>
        <!-- /.row -->
        <div class="row">
            <asp:ScriptManager runat="server" ID="ScriptManager1" />
            <asp:UpdatePanel ID="upCrudGrid" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="GridView1" runat="server"
                        Width="940px" HorizontalAlign="Center"
                        AutoGenerateColumns="false" AllowPaging="true"
                        CssClass="table table-hover table-striped table-bordered table-responsive table-condensed" OnRowCommand="GridView1_RowCommand">
                        <Columns>
                            <asp:ButtonField CommandName="detail"
                                ControlStyle-CssClass="btn btn-info"
                                ButtonType="Button" Text="Détail" HeaderText="Voir détails">
                                <ControlStyle CssClass="btn btn-info"></ControlStyle>
                            </asp:ButtonField>
                            <asp:ButtonField CommandName="editRecord"
                                ControlStyle-CssClass="btn btn-info"
                                ButtonType="Button" Text="Modifier" HeaderText="Modifier l'utilisateur">
                                <ControlStyle CssClass="btn btn-info"></ControlStyle>
                            </asp:ButtonField>
                            <asp:ButtonField CommandName="deleteRecord"
                                ControlStyle-CssClass="btn btn-info"
                                ButtonType="Button" Text="Bannir" HeaderText="Bannir l'utilisateur">
                                <ControlStyle CssClass="btn btn-info"></ControlStyle>
                            </asp:ButtonField>
                            <asp:BoundField DataField="Login_User" HeaderText="Nom d'utilisateur" />
                            <asp:BoundField DataField="Nom_User" HeaderText="Nom" />
                            <asp:BoundField DataField="Prenom_User" HeaderText="Prénom" />
                            <asp:BoundField DataField="Date_Naissance" HeaderText="Date de naissance" />
                            <asp:BoundField DataField="Photo_Profil" HeaderText="Photo de Profil" Visible="false" />
                            <asp:BoundField DataField="Password_User" HeaderText="Mot de passe" Visible="false" />
                            <asp:BoundField DataField="Titre" HeaderText="Titre" Visible="false" />
                            <asp:BoundField DataField="Localisation_User" HeaderText="Localisation" Visible="false" />
                            <asp:BoundField DataField="Date_Inscription" HeaderText="Date d'inscription" />
                            <asp:BoundField DataField="Email" HeaderText="Email" Visible="false" />
                        </Columns>
                    </asp:GridView>
                    <asp:Button ID="btnAdd" runat="server"
                        Text="Add New Record" CssClass="btn btn-info" />
                </ContentTemplate>
                <Triggers>
                </Triggers>
            </asp:UpdatePanel>
        </div>
    </div>
    <!-- Popup détail utilisateur-->
    <div id="detailModal" class="modal" role="dialog" tabindex="-1">
        <div class="modal-header">
            <button id="btnclosegu" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel"></h3>
        </div>
        <asp:Image ID="kkk" runat="server" />
        <div class="modal-body">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:DetailsView ID="DetailsView1" runat="server" CssClass="table table-bordered table-hover" BackColor="White" ForeColor="Black" FieldHeaderStyle-Wrap="false" FieldHeaderStyle-Font-Bold="true" FieldHeaderStyle-BackColor="LavenderBlush" FieldHeaderStyle-ForeColor="Black" BorderStyle="Groove" AutoGenerateRows="False">
                        <Fields>
                            <asp:BoundField DataField="Login_User" HeaderText="Nom d'utilisateur" />
                            <asp:BoundField DataField="Nom_User" HeaderText="Nom" />
                            <asp:BoundField DataField="Prenom_User" HeaderText="Prénom" />
                            <asp:BoundField DataField="Date_Naissance" HeaderText="Date de naissance" />
                            <asp:TemplateField HeaderText="Image View" ControlStyle-Width="200px" ControlStyle-Height="200px">
                                <ItemTemplate>
                                    <asp:Image ID="Image" runat="server" ImageUrl='<%# "Handler.ashx?id=" + Eval("Login_User") %>' />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Password_User" HeaderText="Mot de passe" Visible="false" />
                            <asp:BoundField DataField="Titre" HeaderText="Titre" />
                            <asp:BoundField DataField="Localisation_User" HeaderText="Localisation" />
                            <asp:BoundField DataField="Date_Inscription" HeaderText="Date d'inscription" />
                            <asp:BoundField DataField="Email" HeaderText="Email" />
                        </Fields>
                    </asp:DetailsView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
                    <asp:AsyncPostBackTrigger ControlID="btnAdd" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
            <div class="modal-footer">
                <button id="btnclosegu2" class="btn btn-info">Close</button>
            </div>
        </div>
    </div>
    <!-- Fin Popup détail utilisateur -->

    <div id="editModal" class="modal" tabindex="-1" role="dialog">
        <div class="modal-header">
            <button id="btnclosegu3" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="editModalLabel"></h3>
        </div>
        <asp:UpdatePanel ID="upEdit" runat="server">
            <ContentTemplate>
                <div class="modal-body">
                    <table class="table table-bordered table-condensed table-hover table-responsive">
                        <tr>
                            <td>Login  : 
                            </td>
                            <td>
                                <asp:TextBox CssClass="form-control" ID="txtLogin" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Password : 
                            </td>
                            <td>
                                <asp:TextBox CssClass="form-control" ID="txtPassword" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Nom :
                            </td>
                            <td>
                                <asp:TextBox CssClass="form-control" ID="txtNom" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Prénom :
                            </td>
                            <td>
                                <asp:TextBox CssClass="form-control" ID="txtPrenom" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">Date de naissance :
  <asp:Calendar CssClass="table table-bordered table-responsive" ID="Calendrier" runat="server"></asp:Calendar>
                            </td>
                        </tr>
                        <tr>
                            <td>Photo de Profil :
                            </td>
                            <td>
                                <asp:Image Width="200px" Height="200px" ID="Photo_profil" runat="server"></asp:Image>
                                <input ID="fileup" type="file" name="file" onchange="previewFile()"  runat="server" />
                                 </td>
                        </tr>
                        <tr>
                            <td>Titre : 
                            </td>
                            <td>
                                <asp:TextBox CssClass="form-control" ID="txtTitre" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Localisation : 
                            </td>
                            <td>
                                <asp:TextBox CssClass="form-control" ID="txtLocalisation" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Email  : 
                            </td>
                            <td>
                                <asp:TextBox CssClass="form-control" ID="txtEmail" runat="server"></asp:TextBox>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                   <asp:Button ID="btnupdate" CssClass="btn btn-info" Text="Confirmer la modification" runat="server"  OnClick="btnupdate_Click" />                     
                </div>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
                <asp:AsyncPostBackTrigger ControlID="btnupdate" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
    </div>

    <script src="Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        function previewFile() {

            var preview = document.querySelector('#<%=Photo_profil.ClientID %>');
            var file = document.querySelector('#<%=fileup.ClientID %>').files[0];
            var reader = new FileReader();

            reader.onloadend = function () {
                preview.src = reader.result;
            }

            if (file) {
                reader.readAsDataURL(file);
            } else {
                preview.src = "";
            }
        }
    </script>

</asp:Content>

对于MasterPage:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="administration.SiteMaster" %>

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="utf-8">

    <title>Administration de X</title>

    <!-- Bootstrap -->
    <link href="Content/bootstrap.css" rel="stylesheet"/>

    <!-- CSS personnel-->
    <link href="Content/site.css" rel="stylesheet"/>
       <link rel="stylesheet" href="Content/jquery-ui.css">

    <!-- font-awesome CSS -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
      <!-- morris css -->
    <link rel="stylesheet" href="Content/morris-0.4.3.min.css"/>  
  </head>

  <body>
<form runat="server">
    <div id="wrapper">

      <!-- Sidebar -->
      <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <a class="navbar-brand" href="Default.aspx">Administration de X</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse navbar-ex1-collapse">
            <ul class="nav navbar-nav side-nav">
                <li id="accueil"><a href="/Default"><i class="fa fa-dashboard"></i> Accueil</a></li>
                <li id="users"><a href="/GestionUtilisateurs"><i class="fa fa-users"></i> Gérer les utilisateurs</a></li>
                <li id="pub"><a href="#"><i class="fa fa-comments"></i> Gérer les publications</a></li>
                <li id="recette"><a href="#"><i class="fa fa-cutlery"></i> Gérer les recettes</a></li>
                <li id="prop"><a href="#"><i class="fa fa-exchange"></i> Gérer les propositions</a></li>
            </ul>

          <ul class="nav navbar-nav navbar-right navbar-user">
            <li class="dropdown alerts-dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bell"></i> Notifications <span class="badge">3</span> <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="#">Default <span class="label label-default">Default</span></a></li>
                <li><a href="#">Primary <span class="label label-primary">Primary</span></a></li>
                <li><a href="#">Success <span class="label label-success">Success</span></a></li>
                <li><a href="#">Info <span class="label label-info">Info</span></a></li>
                <li><a href="#">Warning <span class="label label-warning">Warning</span></a></li>
                <li><a href="#">Danger <span class="label label-danger">Danger</span></a></li>
                <li class="divider"></li>
                <li><a href="#">View All</a></li>
              </ul>
            </li>
            <li class="dropdown user-dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> <%= (String)Session["user"] %> <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <!--<li><a href="#"><i class="fa fa-user"></i> Profile</a></li>-->
                <!--<li><a href="#"><i class="fa fa-envelope"></i> Inbox <span class="badge">7</span></a></li>-->
                <li><a href="#" id="btnset"><i class="fa fa-gear"></i> Paramètres</a></li>
                <li class="divider"></li>
                <li><asp:LinkButton ID="linkbtndeco" PostBackUrl="#" runat="server" OnClick="linkbtndeco_Click1" ><i class="fa fa-power-off"></i> déconnexion</asp:LinkButton></li>
              </ul>
            </li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </nav>
        <div id="popup_box">
            <form class="form-horizontal">
                <fieldset>
                    <!-- Form Name -->
                    <legend>Modifier vos données</legend>
                    <!-- Text input-->
                    <div class="control-group">
                        <label class="control-label" for="txtnom">Nom :</label>
                        <div class="controls">
                            <asp:TextBox ID="txtnom" TextMode="SingleLine" required autofocus placeholder="Votre nom" CssClass="input-sm" runat="server"/>
                        </div>
                    </div>

                    <!-- Text input-->
                    <div class="control-group">
                        <label class="control-label" for="txtprenom">Prénom :</label>
                        <div class="controls">
                            <asp:TextBox ID="txtprenom" TextMode="SingleLine" required  placeholder="Votre prénom" CssClass="input-sm" runat="server"/>
                        </div>
                    </div>

                    <!-- Text input-->
                    <div class="control-group">
                        <label class="control-label" for="txtlogin">Nom d'utilisateur :</label>
                        <div class="controls">
                            <asp:TextBox ID="txtlogin" TextMode="SingleLine" required  placeholder="Votre nom d'utilisateur" CssClass="input-sm" runat="server"/>
                        </div>
                    </div>

                    <!-- Password input-->
                    <div class="control-group">
                        <label class="control-label" for="txtpw">Mot de passe :</label>
                        <div class="controls">
                            <asp:TextBox ID="txtpw" TextMode="Password" required  placeholder="Votre mot de passe" CssClass="input-sm" runat="server"/>
                        </div>
                    </div>

                    <!-- Password verification input -->
                    <div class="control-group">
                        <label class="control-label" for="txtpw">Retapez le mot de passe :</label>
                        <div class="controls">
                            <asp:TextBox ID="txtpwverif" TextMode="Password" required  placeholder="Retapez votre MDP" CssClass="input-sm" runat="server"/>
                        </div>
                    </div>

                    <!-- Button -->
                    <div class="control-group">
                        <label class="control-label" for="btnmodif"></label>
                        <div class="controls">
                            <asp:Button ID="btnmodif" CssClass="btn btn-primary" Text="Modifier" runat="server" OnClick="btnmodif_Click"/>
                        </div>
                    </div>

                </fieldset>
            </form>

            <a id="popupBoxClose">Fermer</a>
        </div>
      <asp:ContentPlaceHolder ID="contenu" runat="server">

      </asp:ContentPlaceHolder>
            </div>

    <!-- JavaScript -->
    <script src="Scripts/jquery-1.10.2.js"></script>
    <script src="Scripts/bootstrap.js"></script>

    <!-- Page Specific Plugins -->
    <script src="Scripts/Raphael-Morris/raphael-min.js"></script>
    <script src="Scripts/Raphael-Morris/morris-0.4.3.min.js"></script>
  <script src="Scripts/jquery-ui.js"></script>

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

当我尝试点击&#34; btnupdate&#34;按钮没有任何反应,它甚至没有进入后面的代码中的btnupdate_click()方法。删除表单runat =&#34; server&#34;在母版页中添加一个特定的一个到&#34; GestionUtilisateurs&#34;页面修复了问题,但这不是我需要的主页中的表单。

感谢。

1 个答案:

答案 0 :(得分:0)

问题已解决。我更改了弹出框的z-index属性,以便它现在正在工作。 感谢。