Not able to make button visible from updatepanel

Last post 12-19-2008 5:06 AM by venugopalvalivarthi. 5 replies.

Sort Posts:

  • Not able to make button visible from updatepanel

    10-16-2008, 10:13 AM
    • Member
      point Member
    • Prabha83
    • Member since 10-16-2008, 1:33 PM
    • Posts 11

    Hi,

     I have two buttons search and export to excel.

    When i click Search Button , Gridview will be loaded with search results.

    If there is no record then i want to make export excel button's visible is false.

    Again  I want to make Export excel button visible to true if there is record.

    I  have put grid in updatepanel and it will be triggerred when search button clicked.

    Please help me , how can make button visible which is located out of updated panel.

     Also if i put the button in updatepanel , i am not able to export data to excel.

    Thanks,

    Prabha

  • Re: Not able to make button visible from updatepanel

    10-16-2008, 10:52 AM

    Prabha,

    You cannot refresh an element outside of your update panel, your excel update button, using ajax.  The point of update panels is to determine what you want to be refreshed asynchronously.

    Are you getting an error when you try to put your button inside the update panel?  You could try putting your button inside a different update panel, say UpdatePanel2, and call its Update method: UpdatePanel2.Update(), when the grid is empty.

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Not able to make button visible from updatepanel

    10-17-2008, 5:53 AM
    • Member
      point Member
    • Prabha83
    • Member since 10-16-2008, 1:33 PM
    • Posts 11

    I tried ur solution.

    I have put the Export excel button in another updatepanel and called the mathod Updatepanel2.Update(), but i was getting error message when tried to export gridview data into excel.

    Please give me another solution.

     The below code iam using for export excel:

     Dim strWriter As New StringWriterDim strHtmlWriter As New UI.HtmlTextWriter(strWriter)

    response.Clear()

    response.AddHeader("content-disposition", "attachment;filename=" & strFileName & ".xls")

    response.Charset = "utf-8"

    response.ContentType = "application/vnd.ms-excel"

    gvExcel.Visible = True

    gvExcel.RenderControl(strHtmlWriter)

    response.Write(strWriter.ToString)

    response.End()

    Thanks,

    Prabha

  • Re: Not able to make button visible from updatepanel

    10-17-2008, 11:48 AM
    Answer

    Prabha,

    I understand now.  The visibility of the export button needs to be set asynchronously, but the export button click event needs to cause a full postback.  This is because the update panel technology will not support writing to the HttpResponse object.  To get around this, we can still put the export button inside an update panel, but we need to create a posback trigger to indicate that the export button does not itself initiate an async postback.  I've written a simple example showing how to do this, which you should find helpful:

     

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <script runat="server">
            protected void ShowExportButton(object sender, EventArgs args)
            {
                this.btnExport.Visible = true;
                this.UpdatePanel2.Update();
            }
        </script>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            Make second button visible asynchronously:
            <asp:Button ID="Button1" runat="server"
                    Text="Show" OnClick="ShowExportButton" />
            </ContentTemplate> 
            </asp:UpdatePanel>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Button ID="btnExport" Visible="false" runat="server" Text="Export" />
            </ContentTemplate>
            <Triggers>
            <asp:PostBackTrigger ControlID="btnExport" />
            </Triggers>
            </asp:UpdatePanel>    
        </div>
     

    James

     

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Not able to make button visible from updatepanel

    10-20-2008, 2:33 AM
    • Member
      point Member
    • Prabha83
    • Member since 10-16-2008, 1:33 PM
    • Posts 11

    Thanks for your help.

     It's working now.

  • Re: Not able to make button visible from updatepanel

    12-19-2008, 5:06 AM

    thxs james for me also i am not able to see the data if i keep the updatemode ="conditional" so i am updating the updatepanel after the modalpopp is show

    and i had one more dought james i am having the problem in ajax modalpoup

    i am using modalpoup whn i click on image button i am able to open the modal poup aftert tht i am able to see the modal poup and then if i select any radio button and submit i am able to see one more modalpoup in tht modal poup if i press the enter key the previosu focus on the image button tht is once gain showing on this modal poup can u set how to remove the focus on the image button and set foucs to the current modalpoup up textbox  

     

Page 1 of 1 (6 items)