Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Panels Visible property 1

Status
Not open for further replies.

homeguard

IS-IT--Management
Jul 12, 2007
47
US
So i have a drop down box that say "visable" "yes";"no" and i want make it work with my panel.

How do i do that? I would like to make the drop box show/hide the panel without using a button.

also, whats the differece from typing code into the source window vs the .vb file?

Thanks,
Homeguard
 
Set your DropDown to AutoPostBack=true

On your change event for the dropdown, set panel.Visible = ddl.Selected.Value. when you create your dropdown the values for yes and no should be true and false, respectively.



putting your code in the code behind (.vb) seperates it from the aspx page. There is no other difference except that using the code behind is a heck of a lot easier to work with IMO.

 
Or with just a bit of coding, you can do the same effect on javascript. Saves you a postback too. Just hook on the drop down's appropriate event (something like selectionChanged) and from there set the Panel's (which is probably a DIV when rendered) display/visibility style.

About the codebehinds, from the design point of view, you get a cleaner interface separating the business logic from the UI. Also the parsing overhead on the aspx files will be significantly minimized because the logic is already compiled (no need to parse what's already compiled).

The first time the web application is run, asp.net loads the assembly and runs the requested page. So, the delay during the initial run of the application is expected. But on successive requests, the delay is no longer there.

Try googling on ASP.NET codebehind to find a more technical discussion on this subject.

My $0.02 [wink]
 
So enabling autopostback didnt work. I even set it to when any change on the dropdown it would set the panel to visible.

how would i do this with java? any tutorials?
 
So enabling autopostback didnt work.
Really?
Code:
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
            <asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
            <asp:ListItem Text="No" Value="No"></asp:ListItem>
        </asp:DropDownList>
        <asp:Panel ID="Panel1" runat="server">
            Hello
        </asp:Panel>
Code:
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        If DropDownList1.SelectedItem.Value = "Yes" Then
            Panel1.Visible = True
        Else
            Panel1.Visible = False
        End If
    End Sub



____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
ahh thanks ca8msm got it working, now im wondering if there is a way to make it not scroll up to the top everytime it Auto Post Back?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top