Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2003
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Show <div> on postback

    I'm sure I have pretty simple question but for some reasons I can't find answer

    I have a basic JS function to show an element

    function show(obj1) {
    var div = document.getElementById(obj1);
    div.style.display = 'inline';
    }
    .....

    <a onclick="show('Div')>Show Panel</a>

    <div id="Div" runat="server" style="display: none">
    <table><tr><td>
    ...Controls
    </td></tr>
    <tr><td>
    <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
    </td></tr>
    </table>
    </div>

    Displaying the panel is not a problem but how do I keep it shown on a postback (btnSearch_click)?

    protected void btnSearch_Click(object sender, EventArgs e)
    {
    //Do something
    //tried
    Div.Attributes.Add("display", "inline'");
    //and Div.Style("display") = "inline";
    //and Div.Visible = true;
    }

    no matter what I do, it gets hidden.

  • #2
    New Coder
    Join Date
    Aug 2011
    Posts
    50
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Postback event

    have you tried this :


    Div.Visible = Page.IsPostBack

  • #3
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,739
    Thanks
    41
    Thanked 191 Times in 190 Posts
    i have only ever run into problems with setting runat="server" to my divs.. usually i loose all my CSS attributes... My soltion (and what seems to be "better practice") is "wrapping" the div in question in a panel and showing/hiding the panel on postback... this works better (imo)...

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •