2011-12-16 28 views
0

ウェブフォームのイベント(コントロール、テキストボックス、ボタンなど)が発生しない原因は何だと思いますか?このようなイベントを作成するときに確認し、検討する必要があるものは何ですか?イベントが発生しなかった原因は何ですか?

<%@ Page Language="C#" MasterPageFile="~/App_Theme/TranByEmployeeMaster.master" AutoEventWireup="true" 
    CodeFile="ProcessEmployeePenalty.aspx.cs" Inherits="Transactions_ProcessEmployeePenalty" 
    Title="Untitled Page" %> 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server"> 
    <asp:GridView ID="gvEmployees" runat="server" HeaderStyle-CssClass="HeaderStyle" 
     RowStyle-CssClass="RowStyle" AlternatingRowStyle-CssClass="AlternatingRowStyle" 
     FooterStyle-CssClass="FooterStyleGrid" EmptyDataRowStyle-BackColor="White" AutoGenerateColumns="False" 
     EmptyDataText="No result were found." ShowFooter="true" DataKeyNames="EmployeePenaltyID"> 
     <Columns> 
      <asp:TemplateField HeaderText="No."> 
       <ItemTemplate> 
        <asp:Label ID="lblNo" runat="server" Text='<%# gvEmployees.Rows.Count + 1 %>' /> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Update"> 
       <ItemTemplate> 
        <asp:ImageButton ID="btnUpdateEmployeeGrid" runat="server" ImageUrl="~/App_Resources/images/content/Edit.gif" 
         CommandName="Update" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" /> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:TemplateField HeaderText="Delete"> 
       <ItemTemplate> 
        <asp:ImageButton ID="btnDeleteEmployeeGrid" runat="server" ImageUrl="~/App_Resources/images/content/Delete.png" 
         CommandName="Delete" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" /> 
       </ItemTemplate> 
      </asp:TemplateField> 
      <asp:ButtonField HeaderText="EmployeeID" DataTextField="EmployeeID" /> 
      <asp:ButtonField HeaderText="Penalty Nature" DataTextField="PenaltyNature" /> 
      <asp:ButtonField HeaderText="Penalty Description" DataTextField="PenaltyDescription" /> 
      <asp:ButtonField HeaderText="Penalty Amount" DataTextField="PenaltyAmount" /> 
     </Columns> 
    </asp:GridView> 
    <%--<asp:Button ID="btnAddPenalty" runat="server" Text="Add Penalty" OnClick="btnAddPenalty_Clicked" 
       OnClientClick="return confirm('Are you certain to post the selected cutoff?');" />--%> 
    <asp:ImageButton ID="btnAddPenalty" runat="server" SkinID="Add" OnClick="btnAddPenalty_Clicked" /> 
    <asp:DropDownList ID="sample" runat="server" AutoPostBack="true" OnSelectedIndexChanged="sample_selected"> 
     <asp:ListItem Value="0" Text="Sample0" /> 
     <asp:ListItem Value="1" Text="Sample1" /> 
     <asp:ListItem Value="2" Text="Sample2" /> 
    </asp:DropDownList> 
    <asp:Panel ID="pnlPopUp" runat="server"> 
     <table> 
      <tr> 
       <td> 
        <asp:Label ID="lblsample" runat="server" Text="Employee : " /> 
       </td> 
       <td> 
        <asp:DropDownList ID="ddlEmployees" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <asp:Label ID="Label1" runat="server" Text="Penalty Nature : " /> 
       </td> 
       <td> 
        <asp:TextBox ID="tbxPenaltyNature" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <asp:Label ID="Label2" runat="server" Text="Penalty Description : " /> 
       </td> 
       <td> 
        <asp:TextBox ID="tbxPenaltyDescription" runat="server" TextMode="MultiLine" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <asp:Label ID="Label3" runat="server" Text="Penalty Amount : " /> 
       </td> 
       <td> 
        <asp:TextBox ID="tbxPenaltyAmount" runat="server" /> 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <asp:Button ID="btnClose" runat="server" Text="Close" /> 
       </td> 
       <td> 
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Clicked" /> 
       </td> 
      </tr> 
     </table> 
    </asp:Panel> 
    <asp:Label ID="lblDummy" runat="server" /> 
    <ajax:ModalPopupExtender ID="MP" runat="server" TargetControlID="lblDummy" PopupControlID="pnlPopUp" 
     CancelControlID="btnClose"> 
    </ajax:ModalPopupExtender> 
</asp:Content> 

protected void btnAddPenalty_Clicked(object sender, EventArgs e) 
    { 
     MP.Show(); 
    } 

私はこのページにマスターページを持っていますが、私はこのコードはonclickedイベントを発生しない理由を見ることができません。

は、このコードを検討してください。私はクリックしてImageButtonをクリックして、特定のフィールドに表示されている投稿をクリックしてデータベースに保存するが、onclickedイベントは発生せず、ページのpage_loadイベントのポストバックも表示されないように、modalpopup(ajaxコントロール)いずれかを発射する。

+1

コードを追加してください –

答えて

0

イベントは、publisher-subscriberメカニズムに従います。 Control /オブジェクトは、実装ごとに常にイベントを発生(起動)します。問題はhandlerが付けられているかどうかです。あなたがイベントを購読したい場合は、event handlerに添付して、eventに添付する必要があります。

MSDNの記事 - Raising an EventEvents (C# Programming Guide)をご覧ください。

+0

もう1つの質問は、コントロールにイベントハンドラがあるかどうかを確認する方法です。私は古典的なasp.netページを使用しています。 – Rob

0

自動配線が有効になっていることを確認してください。そうでない場合は、イベントのうちトリガされないものがトリガされます。

0

あなたのjavascriptがエラーを投げている可能性があります。あなたのJavaスクリプトでwindow.onerror関数を試して、アラートを表示させてください。したがって、そこに問題がある場合は、今すぐになります。

0

イベントを登録しませんでしたか(プログラムでも宣言的でも)? AutoEventWireup = "false"でしたか?

+0

いいえ、私のページでautoeventwireup = trueを入力してください – Rob

関連する問題