views:

24

answers:

1

I am firing an event from an ascx control in order to update some controls in the container to which the ascx control belongs.

The ascx control is displayed via a modal popup extender. When I click a button inside the ascx, I fire an event to which the container containing the ascx control is subscribes.

The event delegate is fired and the expected logic is run in the container's code behind, the problem is that any changes made to controls inside not the container aren't updated despite the event logic having been processed. The expected changes are not reflected on the page when the results of the postback is rendered.

Are there any pitfalls I should know of?

The markup for the container

<asp:Panel ID="panelTreeViewAttributesTitle" runat="server">
<asp:Label ID="someLabel" runat="server" Text="Hello Governor" />
<asp:LinkButton ID="LinkButtonEdit" runat="server" Text="(Edit)" />
<ajax:ModalPopupExtender BackgroundCssClass="modalBackground" Enabled="True" 
     ID="btnEdit_ModalPopupExtender" PopupControlID="modalPanel" runat="server"
     TargetControlID="LinkButtonEdit" />
</asp:Panel>
<asp:Panel ID="modalPanel" runat="server" CssClass="modalPopUp" Style="display: none">
    <xxx:customControl runat="server" ID="myCustomControl" />
</asp:Panel>

The code behind for the container

protected void Page_Load(object sender, EventArgs e)
{
myCustomControl.Updated += eventCaptured;
if (IsPostBack) return;
...
}

void eventCaptured(object sender, EventArgs e)
{
someLabel.Text = "Goodbye Governor";
}

The custom control

<script type="text/javascript">
function Update() {
    var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
    if (ajaxManager != null)
    ajaxManager.ajaxRequest("");
    }
</script>
<asp:Panel ID="panelEditPanel" runat="server">
    <asp:Label ID="lblCMA" runat="server" Text="Call me Arnooold." />
</asp:Panel>
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClientClick="Update()" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />

The custom control's code behind

public event EventHandler Updated;

protected void AjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
    //Some DB backend logic
    UpdateFinished();
}

private void UpdateFinished()
{
    if (Updated == null) return;
    Updated(this, null);
}
A: 

Maybe the button click is causing a partial post back instead of a normal, full-page post back. If this is the case, the entire life cycle would run on the server side (including your event handler) but only part of the HTML would be updated on the client side when the response comes back to the browser. "someLabel" could be outside the region that gets updated on the client side.

William Gross