0

I have a custom event that I want to use to display a previously hidden element on my page.

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>

Code behind:

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;
}

the debug-message is displayed. I can place breakpoints in the event-handler and they are reached, but no matter what I try I can't manipulate the page from my event handler. The fsEditPlugin is not a child of anything else that is hidden. Some things I've tried:

//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"));

Nothing seems to work. There isn't anything in my Page_Load that should interfere with the controls.

The event is being fired from another child web user control. So when I press a button in another child web user control I want to make the EditSync-control to become visible.

Johan Hjalmarsson
  • 3,433
  • 4
  • 39
  • 64

1 Answers1

0

Ok, so I finally managed to fix the problem!

The problem was that my button that fired the event was from within a update panel:

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

I solved this by adding the following line to the Page_Load of ctlDelivery:

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

shoutout to EvilDr and his answer to another question

Community
  • 1
  • 1
Johan Hjalmarsson
  • 3,433
  • 4
  • 39
  • 64