How to Show/Hide a Panel upon Click of a Button in ASP.Net










0















I am having issues showing up or hiding a Panel on a button click. By default the panel is hidden but I want the panel to show up once the button is clicked and it is not working for me now.



The only time the panel shows up is when another post-back occurs, like when I select drop down and that triggers a post-back then my panel will show up. I think the issue is that I am using an UpdatePanel and which is only doing a partial post back.



Here is the code where I am using AsyncPostBackTrigger for my control (Button).



<div id="dvGrid" style="padding: 10px; width: 876px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" Width="870px" OnRowDataBound="RowDataBound"
AutoGenerateColumns="False" Font-Names="Arial" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B"
HeaderStyle-BackColor="green" ShowFooter="True" OnPageIndexChanging="OnPaging"
DataKeyNames="DEV_SK">
<AlternatingRowStyle BackColor="#C2D69B" />
<Columns>
<asp:TemplateField ItemStyle-Width="30px" HeaderText="ID" Visible = "false">
<ItemTemplate>
<asp:Label ID="lblDEV_SK" runat="server" Text='<%# Eval("DEV_SK")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="10px" />
</asp:TemplateField>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpdate" />
</Triggers>
</asp:UpdatePanel>
</div>


and here is the the code for the button:



<asp:Button ID="btnUpdate" runat="server" Text="SAVE" OnClick = "Update" Visible = "true" 
Font-Bold="False" Font-Size="Large" Height="30px" Width="157px"/>


and here is the code behind once they click the button:



 protected void Update(object sender, EventArgs e)

Panel1.Visible = true;
//do somthing else




and here is my Panel:



 <div>
<asp:Panel ID="Panel1" runat="server" BorderStyle="Groove" Height="109px" Visible="false"
Width="870px" BackColor="#FFFFE1">
<asp:Label ID="Label2" runat="server" Text="SIGN" Font-Bold="True"
ForeColor="#FF3300"></asp:Label>
<br />
<br />

<asp:Label ID="lblUID" runat="server" Text="User ID:"></asp:Label>
<asp:TextBox ID="txtUID" runat="server" Height="22px" Width="145px"></asp:TextBox> &nbsp;&nbsp;
&nbsp;&nbsp;

<asp:Label ID="lblPass" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPass" runat="server" Height="23px" TextMode="Password" style="margin-top: 0px"></asp:TextBox>
<br />
<br />
&nbsp;<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="183px"
onclick="btnSubmit_Click"
OnClientClick="return confirm('Are you sure you want to submit?');"
Font-Bold="False" Font-Size="Medium" Height="30px"
style="margin-right: 1px" />
<br />
</asp:Panel>

</div>









share|improve this question
























  • Where's actual Panel1 control?

    – Yuriy Galanter
    Jan 13 '14 at 20:40











  • Yuriy, i just added the Panel code in my initial post. Please look at the top

    – moe
    Jan 13 '14 at 20:46











  • So your Panel1 is outside of your UpdatePanel?

    – Yuriy Galanter
    Jan 13 '14 at 20:48











  • yes it is outside of the update panel

    – moe
    Jan 13 '14 at 20:53






  • 1





    Then the button that is designated as AsyncPostBackTrigger for an UpdatePanel will not affect it. You need to either place the panel inside of the first UpdatePanel or inside of UpdatePanel of its own

    – Yuriy Galanter
    Jan 13 '14 at 20:56















0















I am having issues showing up or hiding a Panel on a button click. By default the panel is hidden but I want the panel to show up once the button is clicked and it is not working for me now.



The only time the panel shows up is when another post-back occurs, like when I select drop down and that triggers a post-back then my panel will show up. I think the issue is that I am using an UpdatePanel and which is only doing a partial post back.



Here is the code where I am using AsyncPostBackTrigger for my control (Button).



<div id="dvGrid" style="padding: 10px; width: 876px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" Width="870px" OnRowDataBound="RowDataBound"
AutoGenerateColumns="False" Font-Names="Arial" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B"
HeaderStyle-BackColor="green" ShowFooter="True" OnPageIndexChanging="OnPaging"
DataKeyNames="DEV_SK">
<AlternatingRowStyle BackColor="#C2D69B" />
<Columns>
<asp:TemplateField ItemStyle-Width="30px" HeaderText="ID" Visible = "false">
<ItemTemplate>
<asp:Label ID="lblDEV_SK" runat="server" Text='<%# Eval("DEV_SK")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="10px" />
</asp:TemplateField>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpdate" />
</Triggers>
</asp:UpdatePanel>
</div>


and here is the the code for the button:



<asp:Button ID="btnUpdate" runat="server" Text="SAVE" OnClick = "Update" Visible = "true" 
Font-Bold="False" Font-Size="Large" Height="30px" Width="157px"/>


and here is the code behind once they click the button:



 protected void Update(object sender, EventArgs e)

Panel1.Visible = true;
//do somthing else




and here is my Panel:



 <div>
<asp:Panel ID="Panel1" runat="server" BorderStyle="Groove" Height="109px" Visible="false"
Width="870px" BackColor="#FFFFE1">
<asp:Label ID="Label2" runat="server" Text="SIGN" Font-Bold="True"
ForeColor="#FF3300"></asp:Label>
<br />
<br />

<asp:Label ID="lblUID" runat="server" Text="User ID:"></asp:Label>
<asp:TextBox ID="txtUID" runat="server" Height="22px" Width="145px"></asp:TextBox> &nbsp;&nbsp;
&nbsp;&nbsp;

<asp:Label ID="lblPass" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPass" runat="server" Height="23px" TextMode="Password" style="margin-top: 0px"></asp:TextBox>
<br />
<br />
&nbsp;<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="183px"
onclick="btnSubmit_Click"
OnClientClick="return confirm('Are you sure you want to submit?');"
Font-Bold="False" Font-Size="Medium" Height="30px"
style="margin-right: 1px" />
<br />
</asp:Panel>

</div>









share|improve this question
























  • Where's actual Panel1 control?

    – Yuriy Galanter
    Jan 13 '14 at 20:40











  • Yuriy, i just added the Panel code in my initial post. Please look at the top

    – moe
    Jan 13 '14 at 20:46











  • So your Panel1 is outside of your UpdatePanel?

    – Yuriy Galanter
    Jan 13 '14 at 20:48











  • yes it is outside of the update panel

    – moe
    Jan 13 '14 at 20:53






  • 1





    Then the button that is designated as AsyncPostBackTrigger for an UpdatePanel will not affect it. You need to either place the panel inside of the first UpdatePanel or inside of UpdatePanel of its own

    – Yuriy Galanter
    Jan 13 '14 at 20:56













0












0








0








I am having issues showing up or hiding a Panel on a button click. By default the panel is hidden but I want the panel to show up once the button is clicked and it is not working for me now.



The only time the panel shows up is when another post-back occurs, like when I select drop down and that triggers a post-back then my panel will show up. I think the issue is that I am using an UpdatePanel and which is only doing a partial post back.



Here is the code where I am using AsyncPostBackTrigger for my control (Button).



<div id="dvGrid" style="padding: 10px; width: 876px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" Width="870px" OnRowDataBound="RowDataBound"
AutoGenerateColumns="False" Font-Names="Arial" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B"
HeaderStyle-BackColor="green" ShowFooter="True" OnPageIndexChanging="OnPaging"
DataKeyNames="DEV_SK">
<AlternatingRowStyle BackColor="#C2D69B" />
<Columns>
<asp:TemplateField ItemStyle-Width="30px" HeaderText="ID" Visible = "false">
<ItemTemplate>
<asp:Label ID="lblDEV_SK" runat="server" Text='<%# Eval("DEV_SK")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="10px" />
</asp:TemplateField>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpdate" />
</Triggers>
</asp:UpdatePanel>
</div>


and here is the the code for the button:



<asp:Button ID="btnUpdate" runat="server" Text="SAVE" OnClick = "Update" Visible = "true" 
Font-Bold="False" Font-Size="Large" Height="30px" Width="157px"/>


and here is the code behind once they click the button:



 protected void Update(object sender, EventArgs e)

Panel1.Visible = true;
//do somthing else




and here is my Panel:



 <div>
<asp:Panel ID="Panel1" runat="server" BorderStyle="Groove" Height="109px" Visible="false"
Width="870px" BackColor="#FFFFE1">
<asp:Label ID="Label2" runat="server" Text="SIGN" Font-Bold="True"
ForeColor="#FF3300"></asp:Label>
<br />
<br />

<asp:Label ID="lblUID" runat="server" Text="User ID:"></asp:Label>
<asp:TextBox ID="txtUID" runat="server" Height="22px" Width="145px"></asp:TextBox> &nbsp;&nbsp;
&nbsp;&nbsp;

<asp:Label ID="lblPass" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPass" runat="server" Height="23px" TextMode="Password" style="margin-top: 0px"></asp:TextBox>
<br />
<br />
&nbsp;<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="183px"
onclick="btnSubmit_Click"
OnClientClick="return confirm('Are you sure you want to submit?');"
Font-Bold="False" Font-Size="Medium" Height="30px"
style="margin-right: 1px" />
<br />
</asp:Panel>

</div>









share|improve this question
















I am having issues showing up or hiding a Panel on a button click. By default the panel is hidden but I want the panel to show up once the button is clicked and it is not working for me now.



The only time the panel shows up is when another post-back occurs, like when I select drop down and that triggers a post-back then my panel will show up. I think the issue is that I am using an UpdatePanel and which is only doing a partial post back.



Here is the code where I am using AsyncPostBackTrigger for my control (Button).



<div id="dvGrid" style="padding: 10px; width: 876px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" Width="870px" OnRowDataBound="RowDataBound"
AutoGenerateColumns="False" Font-Names="Arial" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B"
HeaderStyle-BackColor="green" ShowFooter="True" OnPageIndexChanging="OnPaging"
DataKeyNames="DEV_SK">
<AlternatingRowStyle BackColor="#C2D69B" />
<Columns>
<asp:TemplateField ItemStyle-Width="30px" HeaderText="ID" Visible = "false">
<ItemTemplate>
<asp:Label ID="lblDEV_SK" runat="server" Text='<%# Eval("DEV_SK")%>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="10px" />
</asp:TemplateField>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUpdate" />
</Triggers>
</asp:UpdatePanel>
</div>


and here is the the code for the button:



<asp:Button ID="btnUpdate" runat="server" Text="SAVE" OnClick = "Update" Visible = "true" 
Font-Bold="False" Font-Size="Large" Height="30px" Width="157px"/>


and here is the code behind once they click the button:



 protected void Update(object sender, EventArgs e)

Panel1.Visible = true;
//do somthing else




and here is my Panel:



 <div>
<asp:Panel ID="Panel1" runat="server" BorderStyle="Groove" Height="109px" Visible="false"
Width="870px" BackColor="#FFFFE1">
<asp:Label ID="Label2" runat="server" Text="SIGN" Font-Bold="True"
ForeColor="#FF3300"></asp:Label>
<br />
<br />

<asp:Label ID="lblUID" runat="server" Text="User ID:"></asp:Label>
<asp:TextBox ID="txtUID" runat="server" Height="22px" Width="145px"></asp:TextBox> &nbsp;&nbsp;
&nbsp;&nbsp;

<asp:Label ID="lblPass" runat="server" Text="Password:"></asp:Label>
<asp:TextBox ID="txtPass" runat="server" Height="23px" TextMode="Password" style="margin-top: 0px"></asp:TextBox>
<br />
<br />
&nbsp;<asp:Button ID="btnSubmit" runat="server" Text="Submit" Width="183px"
onclick="btnSubmit_Click"
OnClientClick="return confirm('Are you sure you want to submit?');"
Font-Bold="False" Font-Size="Medium" Height="30px"
style="margin-right: 1px" />
<br />
</asp:Panel>

</div>






c# asp.net updatepanel panel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 21 '15 at 19:53









Dan Beaulieu

13.1k1079109




13.1k1079109










asked Jan 13 '14 at 20:25









moemoe

1,7063194161




1,7063194161












  • Where's actual Panel1 control?

    – Yuriy Galanter
    Jan 13 '14 at 20:40











  • Yuriy, i just added the Panel code in my initial post. Please look at the top

    – moe
    Jan 13 '14 at 20:46











  • So your Panel1 is outside of your UpdatePanel?

    – Yuriy Galanter
    Jan 13 '14 at 20:48











  • yes it is outside of the update panel

    – moe
    Jan 13 '14 at 20:53






  • 1





    Then the button that is designated as AsyncPostBackTrigger for an UpdatePanel will not affect it. You need to either place the panel inside of the first UpdatePanel or inside of UpdatePanel of its own

    – Yuriy Galanter
    Jan 13 '14 at 20:56

















  • Where's actual Panel1 control?

    – Yuriy Galanter
    Jan 13 '14 at 20:40











  • Yuriy, i just added the Panel code in my initial post. Please look at the top

    – moe
    Jan 13 '14 at 20:46











  • So your Panel1 is outside of your UpdatePanel?

    – Yuriy Galanter
    Jan 13 '14 at 20:48











  • yes it is outside of the update panel

    – moe
    Jan 13 '14 at 20:53






  • 1





    Then the button that is designated as AsyncPostBackTrigger for an UpdatePanel will not affect it. You need to either place the panel inside of the first UpdatePanel or inside of UpdatePanel of its own

    – Yuriy Galanter
    Jan 13 '14 at 20:56
















Where's actual Panel1 control?

– Yuriy Galanter
Jan 13 '14 at 20:40





Where's actual Panel1 control?

– Yuriy Galanter
Jan 13 '14 at 20:40













Yuriy, i just added the Panel code in my initial post. Please look at the top

– moe
Jan 13 '14 at 20:46





Yuriy, i just added the Panel code in my initial post. Please look at the top

– moe
Jan 13 '14 at 20:46













So your Panel1 is outside of your UpdatePanel?

– Yuriy Galanter
Jan 13 '14 at 20:48





So your Panel1 is outside of your UpdatePanel?

– Yuriy Galanter
Jan 13 '14 at 20:48













yes it is outside of the update panel

– moe
Jan 13 '14 at 20:53





yes it is outside of the update panel

– moe
Jan 13 '14 at 20:53




1




1





Then the button that is designated as AsyncPostBackTrigger for an UpdatePanel will not affect it. You need to either place the panel inside of the first UpdatePanel or inside of UpdatePanel of its own

– Yuriy Galanter
Jan 13 '14 at 20:56





Then the button that is designated as AsyncPostBackTrigger for an UpdatePanel will not affect it. You need to either place the panel inside of the first UpdatePanel or inside of UpdatePanel of its own

– Yuriy Galanter
Jan 13 '14 at 20:56












1 Answer
1






active

oldest

votes


















0














Since you already have the IDs of you DOM elements, you can achieve this by using JQuery.



<head>
<script src='https://code.jquery.com/jquery-1.12.4.min.js' >
<script>

$(document).ready( function()
$('#btnSubmit').click(function(e)
$('#Panel1').toggle(); //Show or Hide
e.preventDefault();
);

);
</script>





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21100696%2fhow-to-show-hide-a-panel-upon-click-of-a-button-in-asp-net%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Since you already have the IDs of you DOM elements, you can achieve this by using JQuery.



    <head>
    <script src='https://code.jquery.com/jquery-1.12.4.min.js' >
    <script>

    $(document).ready( function()
    $('#btnSubmit').click(function(e)
    $('#Panel1').toggle(); //Show or Hide
    e.preventDefault();
    );

    );
    </script>





    share|improve this answer



























      0














      Since you already have the IDs of you DOM elements, you can achieve this by using JQuery.



      <head>
      <script src='https://code.jquery.com/jquery-1.12.4.min.js' >
      <script>

      $(document).ready( function()
      $('#btnSubmit').click(function(e)
      $('#Panel1').toggle(); //Show or Hide
      e.preventDefault();
      );

      );
      </script>





      share|improve this answer

























        0












        0








        0







        Since you already have the IDs of you DOM elements, you can achieve this by using JQuery.



        <head>
        <script src='https://code.jquery.com/jquery-1.12.4.min.js' >
        <script>

        $(document).ready( function()
        $('#btnSubmit').click(function(e)
        $('#Panel1').toggle(); //Show or Hide
        e.preventDefault();
        );

        );
        </script>





        share|improve this answer













        Since you already have the IDs of you DOM elements, you can achieve this by using JQuery.



        <head>
        <script src='https://code.jquery.com/jquery-1.12.4.min.js' >
        <script>

        $(document).ready( function()
        $('#btnSubmit').click(function(e)
        $('#Panel1').toggle(); //Show or Hide
        e.preventDefault();
        );

        );
        </script>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 31 '16 at 7:53









        Mihir KaleMihir Kale

        5941614




        5941614





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21100696%2fhow-to-show-hide-a-panel-upon-click-of-a-button-in-asp-net%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3