ugly code for FileUpload+UpdatePanel workaround

I won’t be keeping it like this (because it’s making me vomit a little in my mouth), but it works and I figured I’d post it before killing this off and going a different direction.  I have no doubt with my current theme this will get cut off badly, but I’m hoping RSS readers handle it fine 🙂

protected void gvActiveRequests_RowDataBound(object sender, GridViewRowEventArgs e)
{
    // HACKY!
    //
    // We need the FileUpload control to work under a full postback (it doesn't work under
    // a normal UpdatePanel async postback).  Because of that, we need the button that
    // triggers it to trigger a full postback, so for each "submit" button, we add it as
    // a postback trigger.  The problem is that when the GridView first loads, none of
    // those buttons are visible.  By the time the gridview goes into edit mode, modifying
    // the triggers of the updatepanel doesn't help because we're only doing a partial/async
    // update.  Because of that, we have to cause the button that puts it into edit mode
    // (Change Status) to *also* do a full postback, for the only reason being that we need
    // the adding of the submit buttons to happen during a full postback so it actually "takes"
    // on the client side (since the contents of the updatepanel are what gets updated, the
    // triggers collection does not).
    //
    // Got that?  Good.
    var submitButton = e.Row.FindControl("btnSubmitStatusChange");
    if (submitButton != null)
    {
        this.Master.ScriptManager.RegisterPostBackControl(submitButton);
    }
    var changeStatusButton = e.Row.FindControl("btnChangeStatus");
    if (changeStatusButton != null)
    {
        this.Master.ScriptManager.RegisterPostBackControl(changeStatusButton);
    }
}

Advertisements