locked
button not firing when put inside gridview RRS feed

  • Question

  • User-1706751376 posted

    Hi, My gridview is placed inside UpdatePanel. This I ave used to prevent page refresh in paging. I have also a button inside the gridview. After I put the UpdatePanel, it stops pagerefresh on paging click but it has also stopped click event of button.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:GridView ID="GridView1" AllowPaging="true" PagerStyle-CssClass="pgr" OnRowDataBound="GridView1_RowDataBound"
    AlternatingRowStyle-CssClass="alt" AutoGenerateColumns="false" runat="server"
    PageSize="8" OnPageIndexChanging="GridView1OnPageIndexChanging" DataKeyNames="MainBreakDownReasonID">

    <HeaderStyle BackColor="#465c71" ForeColor="White" />
    <Columns>
    <asp:BoundField DataField="MainBreakDownReason" ItemStyle-Width="330" HeaderText="Process" />
    <asp:BoundField DataField="MainBreakDownReasonCount" ItemStyle-Width="130" HeaderText="Count" />
    <asp:BoundField DataField="BreakDownTime" HeaderText="Time(mins)" ItemStyle-Width="130"/>

    <asp:TemplateField ItemStyle-Width="30" >
    <ItemTemplate>
    <asp:Button ID="Button1"  Text="Get Trend" runat="server" OnClick="GridView1Button1_Click1"/>
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>

    </asp:GridView>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="PageIndexChanging" />
    <%--<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />--%>
    </Triggers>
    </asp:UpdatePanel>

    Please suggest me what wrong I am doing.

    I have also tried doing this:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    Button button = (Button)e.Row.FindControl("Button1");
    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();

    trigger.ControlID = button.UniqueID;
    trigger.EventName = "Click";
    UpdatePanel1.Triggers.Add(trigger);

    ScriptManager1.RegisterAsyncPostBackControl(button);
    }
    }

    but nothing works..

    pls help ..

    Saturday, June 11, 2016 3:05 PM

Answers

  • User-1716253493 posted

    paging : try set rowcommand event to trigger

    button1 : set button1 triger

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
    {  
        Button button1 = e.Row.FindControl("Button1") as Button;
        ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(button1);  
    } 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 12, 2016 8:42 AM
  • User61956409 posted

    Hi vishvishvish,

    You could try to put the both ModalPopupExtender control, chart2 and Panel5 in ContentTemplate of UpdatePanel.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 16, 2016 9:13 AM

All replies

  • User-1716253493 posted

    paging : try set rowcommand event to trigger

    button1 : set button1 triger

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)  
    {  
        Button button1 = e.Row.FindControl("Button1") as Button;
        ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(button1);  
    } 
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 12, 2016 8:42 AM
  • User-1706751376 posted

    Hi.. thanks for the reply .. i am able to get the post back event of the button .. thanks .. 

    i have a chart also on the page .. which should be displayed over the click of button .. now i am getting the button click .. but chart is not displaying .. if i put the chart inside the update panel .. it throws error . i am not sure if we can put asp.chart into update panel or not.. pls help if you know ..

    Sunday, June 12, 2016 10:48 AM
  • User61956409 posted

    Hi vishvishvish,

    i have a chart also on the page .. which should be displayed over the click of button .. now i am getting the button click .. but chart is not displaying .. if i put the chart inside the update panel .. it throws error .

    Could you share us the error message? If you put the Chart inside UpdatePanel control, you could try to call UpdatePanel.Update() method to update the content of UpdatePanel control in button click event.

    Best Regards,

    Fei Han

    Monday, June 13, 2016 5:16 AM
  • User-1706751376 posted

    Hi Fei Han,

    when i try putting the  panel where this chart control reside inside a update panel like :

    <asp:UpdatePanel ID="UpdatePanel3" ChildrenAsTriggers="true" runat="server">
    <ContentTemplate>
    <asp:Panel ID="Panel4" Visible="false" GroupingText="Break Down Process with Reasons"
    runat="server" Width="100%" >
    <asp:Chart ID="chart2" runat="server" Width="512px" IsMapAreaAttributesEncoded="True"
    EnableViewState="True">
    <Series>
    <asp:Series Name="Series1" ChartType="Bar" XValueMember="FiscalWeek"
    YValueMembers="NumRawAbends">
    </asp:Series>
    </Series>
    <ChartAreas>
    <asp:ChartArea Name="ChartArea1">
    </asp:ChartArea>
    </ChartAreas>
    </asp:Chart>
    </asp:Panel>
    </ContentTemplate></asp:UpdatePanel>

    I get error :

    An extender can't be in a different UpdatePanel than the control it extends.

    and below is the complete stack trace:

    Stack Trace:

    [InvalidOperationException: An extender can't be in a different UpdatePanel than the control it extends.]
       System.Web.UI.ExtenderControl.RegisterWithScriptManager() +542
       System.Web.UI.ExtenderControl.OnPreRender(EventArgs e) +45
       AjaxControlToolkit.ExtenderControlBase.OnPreRender(EventArgs e) +64
       AjaxControlToolkit.ModalPopupExtender.OnPreRender(EventArgs e) +188
       System.Web.UI.Control.PreRenderRecursiveInternal() +83
       System.Web.UI.Control.PreRenderRecursiveInternal() +155
       System.Web.UI.Control.PreRenderRecursiveInternal() +155
       System.Web.UI.Control.PreRenderRecursiveInternal() +155
       System.Web.UI.Control.PreRenderRecursiveInternal() +155
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974


    and below is the complete aspx html :

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" MaintainScrollPositionOnPostback="true" AutoEventWireup="true"
    CodeBehind="BreakDownAnalysis.aspx.cs" Inherits="Addverb.WebForm1" %>

    <%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="Styles/Gridstyle.css" rel="stylesheet" type="text/css" />

    <style type="text/css">

    body {
    background-color: #f4f4f4;
    color: #5a5656;
    font-family: 'Open Sans', Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.5em;
    }

    .LargeTextboxId {
    height:33px;
    left:0;
    line-height:33px;
    padding:8px 8px 7px;
    top:0;
    width:175px;
    }
    </style>
    </asp:Content>

    <asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <script type="text/javascript">
    function validate() {
    var date1 = document.getElementById("MainContent_dtEndDate");
    var date2 = document.getElementById("MainContent_dtStartDatePop");
    var date3 = document.getElementById("MainContent_dtEndDatePop");
    if (date1.value > date2.value) {
    alert('Evaluation Start Date should greater than Analysis End Date');
    return false;
    }
    else if (date3.value <= date2.value) {
    alert('Evaluation End Date should greater than Evalutation Start Date');
    return false;
    }

    if (confirm("Do you want to save the data?"))
    //docume.focus[0].submit();
    return true;
    else
    return false;
    }
    </script>
    <table width="100%" style="border: thin solid #C0C0C0">
    <tr>
    <td class="style2">

    <asp:Label ID="Label1" runat="server" Text="Select Line :"></asp:Label>

    </td>
    <td class="style1">
    <asp:DropDownList ID="DropDownList1" runat="server">
    </asp:DropDownList>
    </td>
    <td class="style3" align="right">

    <asp:Label ID="Label2" runat="server" Text="Start Date :"></asp:Label>

    </td>
    <td class="style4">
    <asp:TextBox ID="dtStartDate" Text="11/3/2015" runat="server" ></asp:TextBox></td>
    <td align="left">
    <asp:ImageButton ID="Image1" ImageUrl="~/Image/calender.png" runat="server" />
    <ajaxToolkit:CalendarExtender ID="CalendarExtender1" PopupButtonID="Image1" TargetControlID="dtStartDate" TodaysDateFormat="DD/MM/YYYY" runat="server" />
    </td>
    <td class="style5" align="right">
    <asp:Label ID="Label3" runat="server" Text="End Date :"></asp:Label>
    </td>
    <td class="style2">
    <asp:TextBox ID="dtEndDate" Text="11/30/2015" runat="server"></asp:TextBox></td>
    <td align="left" class="style6">
    <asp:ImageButton ID="ImageButton1" ImageUrl="~/Image/calender.png" runat="server" />
    <ajaxToolkit:CalendarExtender ID="CalendarExtender2" PopupButtonID="ImageButton1" TargetControlID="dtEndDate" TodaysDateFormat="DD/MM/YYYY" runat="server" />
    </td>
    <td class="style8" align="Right">
    <asp:Label ID="Label4" runat="server" Text="Duration :"></asp:Label>
    </td>
    <td class="style9">
    <asp:DropDownList ID="ddlDuration" runat="server" >
    <asp:ListItem Selected="True" Value="0">--Select--</asp:ListItem>
    <asp:ListItem Value="1">Last 1 Day</asp:ListItem>
    <asp:ListItem Value="2">Last 1 Week</asp:ListItem>
    <asp:ListItem Value="3">Last 1 Month</asp:ListItem>
    <asp:ListItem Value="4">Last 1 Year</asp:ListItem>
    </asp:DropDownList>
    </td>
    <td class="style9" align="right">
    <asp:Button ID="Button1" runat="server" Text="Search" onclick="Button1_Click"
    style="margin-left: 0px" />
    </td>
    </tr>

    </table>
    <table width="100%" style="height: 228px">
    <tr>
    <td height="150px" class="style7" valign="top">

    <asp:Panel ID="Panel1" Visible="false" GroupingText="Breaking Process" runat="server" Width="100%" >
    <asp:Chart ID="PieChart" runat="server" Width="509px">
    <Series>
    <asp:Series Name="Series1" ChartType="Pie">

    </asp:Series>
    </Series>
    <ChartAreas>
    <asp:ChartArea Name="ChartArea1">
    </asp:ChartArea>
    </ChartAreas>
    </asp:Chart>

    </asp:Panel>

    </td>
    <td height="150px" valign="top" width="50%">
    <asp:Panel ID="Panel2" Visible="false" Width="100%" GroupingText="Break Down Process"
    runat="server"
    >
    <asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers="true" runat="server">
    <ContentTemplate>
    <asp:GridView ID="GridView1" AllowPaging="true" PagerStyle-CssClass="pgr"
    AlternatingRowStyle-CssClass="alt" AutoGenerateColumns="false" runat="server"
    PageSize="8" OnPageIndexChanging="GridView1OnPageIndexChanging" OnRowCommand="GridView1_RowCommand" DataKeyNames="MainBreakDownReasonID">

    <HeaderStyle BackColor="#465c71" ForeColor="White" />
    <Columns>
    <asp:BoundField DataField="MainBreakDownReason" ItemStyle-Width="330" HeaderText="Process" />
    <asp:BoundField DataField="MainBreakDownReasonCount" ItemStyle-Width="130" HeaderText="Count" />
    <asp:BoundField DataField="BreakDownTime" HeaderText="Time(mins)" ItemStyle-Width="130"/>
    <%--<asp:BoundField DataField="MainBreakDownReasonID" HeaderText="Time(mins)" ItemStyle-Width="130" />--%>
    <asp:TemplateField ItemStyle-Width="30" >
    <ItemTemplate>
    <asp:Button ID="Button1" CommandName="showGarmentsCmd" CommandArgument='<%#Eval("MainBreakDownReasonID")%>' Text="Get Trend" runat="server" />
    </ItemTemplate>
    </asp:TemplateField>

    </Columns>
    </asp:GridView>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
    <asp:PostBackTrigger ControlID="chart2" />
    <%--<asp:AsyncPostBackTrigger ControlID="Button1" />--%>
    </Triggers>
    </asp:UpdatePanel>
    <asp:CheckBox ID="chkMainReasonNotSpecified" AutoPostBack="true" Text="Include main reason not specified"
    runat="server" oncheckedchanged="chkMainReasonNotSpecified_CheckedChanged" />

    </asp:Panel>
    </td>
    </tr>
    </table>
    <table width="100%">
    <tr>
    <td width="50%" valign="top" >
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
    <asp:Panel ID="Panel3" Visible="false" GroupingText="Break Down Process with Reasons"
    runat="server" Width="100%" >

    <asp:GridView ID="dataGridView1" AllowPaging="true" PagerStyle-CssClass="pgr"
    AlternatingRowStyle-CssClass="alt" AutoGenerateColumns="true" runat="server"
    PageSize="5" OnPageIndexChanging="OnPageIndexChanging" >
    <HeaderStyle BackColor="#465c71" ForeColor="White" />
    </asp:GridView>


    </asp:Panel>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
    <%--<asp:AsyncPostBackTrigger ControlID="Button1" />--%>
    </Triggers>
    </asp:UpdatePanel>
    </td>
    <td valign="top">
    <asp:UpdatePanel ID="UpdatePanel3" ChildrenAsTriggers="true" runat="server">
    <ContentTemplate>
    <asp:Panel ID="Panel4" Visible="false" GroupingText="Break Down Process with Reasons"
    runat="server" Width="100%" >

    <asp:Chart ID="chart2" runat="server" Width="512px" IsMapAreaAttributesEncoded="True"
    EnableViewState="True">
    <Series>
    <asp:Series Name="Series1" ChartType="Bar" XValueMember="FiscalWeek"
    YValueMembers="NumRawAbends">
    </asp:Series>
    </Series>
    <ChartAreas>
    <asp:ChartArea Name="ChartArea1">
    </asp:ChartArea>
    </ChartAreas>

    </asp:Chart>

    </asp:Panel>
    </ContentTemplate></asp:UpdatePanel>

    </td>
    </tr>
    </table>


    <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mpe" runat="server"
    PopupControlID="Panel5" TargetControlID="chart2" BackgroundCssClass="modalBackground" CancelControlID = "btnHide">
    </ajaxToolkit:ModalPopupExtender>
    <asp:Panel ID="Panel5" runat="server" CssClass="modalPopup" Style="display: none">

    <div>
    <div class="header">
    Why Why Analysis
    </div>
    <fieldset>
    <legend>Analysis</legend>
    <table width="100%" bgcolor="#0099CC">
    <tr>
    <td style="width:20%">
    <asp:Label ID="Label51" runat="server" ForeColor="White" Text="Line"></asp:Label></td>
    <td style="width:30%"><asp:Label ID="lblLinePop" Font-Bold="true" ForeColor="White" runat="server" Text=""></asp:Label></td>
    <td style="width:20%"><asp:Label ID="Label61" runat="server" ForeColor="White" Text="Machine"></asp:Label></td>
    <td style="width:30%"><asp:Label ID="lblMacihnePop" Font-Bold="true" ForeColor="White" runat="server" Text=""></asp:Label></td>
    </tr>
    <tr>
    <td style="width:20%">
    <asp:Label ID="Label52" runat="server" ForeColor="White" Text="fault"></asp:Label></td>
    <td style="width:30%"><asp:Label ID="lblFaultPop" Font-Bold="true" ForeColor="White" runat="server" Text=""></asp:Label></td>
    <td style="width:20%"></td>
    <td style="width:30%"></td>
    </tr>
    <tr><td style="width:20%"><asp:Label ID="Label5" ForeColor="White" runat="server" Text="Start Date"></asp:Label></td>
    <td style="width:30%"><asp:Label ID="lblStartDatePop" Font-Bold="true" ForeColor="White" runat="server" Text=""></asp:Label></td>
    <td style="width:20%"><asp:Label ID="Label6" ForeColor="White" runat="server" Text="End Date"></asp:Label></td>
    <td style="width:30%"><asp:Label ID="lblEndDatePop" Font-Bold="true" ForeColor="White" runat="server" Text=""></asp:Label></td>
    </tr>
    </table></fieldset>
    </div>
    <div>
    <%--<asp:Panel ID="Panel6" Visible="true" GroupingText="Evaluation" runat="server" Width="100%" >--%>
    <%--<div class="header">
    OEE Analysis
    </div>--%>
    <fieldset>
    <legend>Evaluation</legend>
    <table width="100%">
    <tr><td style="width:20%"><asp:Label ID="Label53" runat="server" Text="Start Date"></asp:Label></td>
    <td style="width:30%"><asp:TextBox ID="dtStartDatePop" runat="server" ></asp:TextBox>
    <asp:ImageButton ID="ImageButton2" ImageUrl="~/Image/calender.png" runat="server" />
    <ajaxToolkit:CalendarExtender ID="CalendarExtender3" PopupButtonID="ImageButton2" TargetControlID="dtStartDatePop" TodaysDateFormat="DD/MM/YYYY" runat="server" /></td>
    <td style="width:20%"><asp:Label ID="Label54" runat="server" Text="End Date"></asp:Label></td>
    <td style="width:30%"><asp:TextBox ID="dtEndDatePop" runat="server" ></asp:TextBox>
    <asp:ImageButton ID="ImageButton3" ImageUrl="~/Image/calender.png" runat="server" />
    <ajaxToolkit:CalendarExtender ID="CalendarExtender4" PopupButtonID="ImageButton3" TargetControlID="dtEndDatePop" TodaysDateFormat="DD/MM/YYYY" runat="server" /></td>
    </tr>
    <tr>
    <td width="20%">
    <asp:Label ID="Label7" runat="server" Text="Why #1"></asp:Label></td>
    <td width="30%">
    <asp:TextBox ID="txtWhy1" runat="server" CssClass="LargeTextboxId" TextMode="MultiLine"></asp:TextBox></td>
    <td width="20%">
    <asp:Label ID="Label9" runat="server" Text="Why #2"></asp:Label></td>
    <td width="30%">
    <asp:TextBox ID="txtWhy2" runat="server" CssClass="LargeTextboxId" TextMode="MultiLine"></asp:TextBox></td>
    </tr>
    <tr>
    <td width="20%">
    <asp:Label ID="Label8" runat="server" Text="Why #3"></asp:Label></td>
    <td width="30%">
    <asp:TextBox ID="txtWhy3" runat="server" CssClass="LargeTextboxId" TextMode="MultiLine"></asp:TextBox></td>
    <td width="20%">
    <asp:Label ID="Label10" runat="server" Text="Why #4"></asp:Label></td>
    <td width="30%">
    <asp:TextBox ID="txtWhy4" runat="server" CssClass="LargeTextboxId" TextMode="MultiLine"></asp:TextBox></td>
    </tr>
    <tr>
    <td width="20%">
    <asp:Label ID="Label11" runat="server" Text="Why #5"></asp:Label></td>
    <td width="30%">
    <asp:TextBox ID="txtWhy5" runat="server" CssClass="LargeTextboxId" TextMode="MultiLine"></asp:TextBox></td>
    <td width="20%">
    <asp:Label ID="Label12" runat="server" Text="Preventive Action"></asp:Label></td>
    <td width="30%">
    <asp:TextBox ID="txtPAction" runat="server" CssClass="LargeTextboxId" TextMode="MultiLine"></asp:TextBox></td>
    </tr>
    </table></fieldset>
    <%-- </asp:Panel>--%>
    </div>
    <div class="Controls" align="center">
    <asp:UpdatePanel ID="UpdatePanelsHospital" runat="server" UpdateMode="always">
    <ContentTemplate>
    <asp:Button ID="btnSave" OnClientClick="return validate();" OnClick="btnSave_Click" runat="server" Text="Save" />
    <asp:Button ID="btnHide" runat="server" Text="Close" />
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" />
    <asp:AsyncPostBackTrigger ControlID="btnHide" EventName="Click" />
    </Triggers>

    </asp:UpdatePanel>
    </div>

    </asp:Panel>

    <asp:Panel ID="pnlPopUp" style="display: none" GroupingText="Break Down Process with Reasons"
    runat="server" >

    </asp:Panel>

    </asp:Content>




     

    Tuesday, June 14, 2016 4:40 PM
  • User61956409 posted

    Hi vishvishvish,

    You could try to put the both ModalPopupExtender control, chart2 and Panel5 in ContentTemplate of UpdatePanel.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 16, 2016 9:13 AM