2016-05-02 9 views
0

私のカスタムイベントは、私のページ上に以前隠れていた要素を表示するために使用します。カスタムイベント内で何もできません

ASPX:

<%@ Register Src="~/Controls/EditSync.ascx" TagPrefix="IP" TagName="EditSync" %> 

<asp:Content ID="main" ContentPlaceHolderID="body" runat="server"> 

//Some unrelated controls 

    <fieldset id="fsEditPlugin" runat="server" class="inputForm" style="width:450px;" visible="false"> 
     <IP:EditSync id="ctlEditSync" runat="server" /> 
    </fieldset> 
</asp:Content> 

コードの背後にある:

protected void Page_Load(object sender, EventArgs e) 
{ 
    this.ctlDelivery.EditPlugin += new EventHandler(onEditPlugin); 
    if (!Page.IsPostBack) 
    { 
     //Some more unrelated things 
    } 
} 

public void onEditPlugin(object sender, EventArgs e) 
{ 
    System.Diagnostics.Debug.Write(((ip.Controls.EditPluginEventArgs)e).type); 
    fsEditPlugin.Visible = true; 
} 

デバッグメッセージが表示されます。私はイベントハンドラにブレークポイントを置くことができますが、それらに到達しましたが、何を試みても、私のイベントハンドラからページを操作することはできません。 fsEditPluginは、隠されているものの子ではありません。私が試したことのいくつか:

//I've tried this: 
<fieldset id="fsEditPlugin" runat="server" class="inputForm" style="width:450px; display:none;"> 
//code behind: 
fsEditPlugin.Style.Add("display", "inline"); 

//I've tried this: 
<fieldset id="fsEditPlugin" runat="server" class="inputForm" style="width:450px;"> 
</fieldset> 
//Code behind: 
fsEditPlugin.Controls.Add(new LiteralControl("TEST")); 

何もないようです。私のPage_Loadには、コントロールを妨害するものはありません。

他の子Webユーザーコントロールからイベントが発生しています。だから、別の子Webユーザーコントロールのボタンを押すと、EditSyncコントロールが表示されるようにしたいと考えています。

+0

これはあなたのコード全体ではありません。ここで 'onEditPlugin'を登録しないからです。また、 'IP:EditSync'とは何ですか? –

+0

fsEditPlugin.Visibleのデフォルト値をtrueに設定した場合、それを表示できますか、それでも見えませんか? –

+0

@PatrickHofmanは私に秒を与え、コードを追加します –

答えて

0

私はついにこの問題を解決できました。

問題は、イベントを解雇私のボタンは、更新パネル内からということでした。

<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <IP:Delivery id="ctlDelivery" runat="server" /> <% /* this is a web user control */ %> 
    </ContentTemplate> 
</asp:UpdatePanel> 

私はctlDeliveryのPage_Loadのに次の行を追加することで、これを解決:

ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(btnEdit); //btnEdit is the button that fires my custom event. 

shoutout to EvilDr and his answer to another question

関連する問題