Link to home
Start Free TrialLog in
Avatar of alik13
alik13Flag for United States of America

asked on

Can not call a method that is located outside the AJAX UpdatePanel

I have AJAX UpdatePanel wrapped around GridView control. When user clicks on the button inside the panel I need to display
message in the Label control that is located outside the UpdatePanel. I need to call method that will show the message.
In a debug mode I placed a breakpoint to the method call it stops there and it seems that partial page rendering does not allow to call methods outside the UpdatePanel. Any suggestions how to call the method from the UpdatePanel:

Here the code snippet:

#region GridView_OnRowCommand methods

    protected void gvUnpostedTransSummary_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName.Equals("post"))
        {  this.GetTransactionArguments(e.CommandArgument.ToString()); }  
       
    }

    private void GetTransactionArguments(string rowID)
    {
        int row = -1;
        string agencyID = string.Empty;
        decimal total = 0.0m;
        string userID = string.Empty;

        int.TryParse(rowID as string, out row);

        if (row != -1)
        {
            GridViewRow selectedRow = gvUnpostedTransSummary.Rows[row];

            agencyID = ((Label)selectedRow.FindControl("lblAgencyID")).Text;
            total = Convert.ToDecimal(((Label)selectedRow.FindControl("lblTotal")).Text);
            userID = ((Label)selectedRow.FindControl("lblUserID")).Text;
                                 
        }
        else
        {          
            string msg = "Unexpected error has occured!Please contact IT Department";
           
            this.SetInfoMessage(msg,InfoMsgColor.Maroon);   // This method is defined in the code-behind. It never gets called!!!
     
        }
 
    }


    #endregion

Please advice!


ASKER CERTIFIED SOLUTION
Avatar of zkeown
zkeown
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alik13

ASKER

Thank you! I will try it.
Avatar of alik13

ASKER

I decided to give it its own UpdatePanel and set a trigger to the GridView's RowCommand event.

<ContentTemplate>
                                    <asp:Label ID="lblInfo" runat="server" Visible="False" Width="290px"></asp:Label>
                                </ContentTemplate>
                                <Triggers >
                                 <ajax:AsyncPostBackTrigger ControlID ="gvUnpostedTransSummary" EventName ="gvUnpostedTransSummary_OnRowCommand" />
                                </Triggers>
                            </ajax:UpdatePanel>

but when I click on the form I get the following error message:

"Could not find an event named 'gvUnpostedTransSummary_OnRowCommand' on associated control 'gvUnpostedTransSummary' for the trigger in UpdatePanel 'upInfo'."
Avatar of alik13

ASKER

Never mind guys,  I found the solution.

<Triggers >
        <ajax:AsyncPostBackTrigger ControlID ="gvUnpostedTransSummary" EventName "RowCommand" />      </Triggers>

  Solution:  instead of using EventName ="OnRowCommand" like in the origanal GridView, I need to change it to
        EventName ="RowCommand"

Thank you guys!