Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2010, 01:19 PM
Authorized User
 
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Make Panel visible with Hyperlink

Hi!

Is it possible to make a Panel visible by clicking on a Hyperlink? I know this works well with RadioButtonLists, but cannot figure out if it works with Hyperlinks. If yes, what to I write? I am using Visual Basic.

Cheers
Peter
 
Old August 1st, 2010, 03:45 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You could. However, since HyperLink render as a client side link, you need to pass some state in the URL that tells the panel to hide itself when the page gets requested. E.g.:

SomePage.aspx?HidePanel=True

Then in SomePage.aspx, you access Request.QueryString.Get("HidePanel") and when it contains the value True, you hide the panel.

However, if it's appearance (e.g. text that looks like a link) rather than behavior (e.g. a HyperLink versus another control), I think you're better off using a LinkButton. At the client, it looks like a HyperLink, but it submits back to the server (to the page where it's used) where you can handle its Click event and hide the Panel.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 2nd, 2010, 11:42 AM
Authorized User
 
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi!

Does this mean I need to have another page with data that loads inside the Panel, like an iframe, or have I misunderstood? Otherwise it sounds like a LinkButton is a better alternative. The way I understand your description is that a LinkButton is a "fake" hyperlink that loads a Panel when you click on it. If so, that's what I was looking for.

Cheers
Peter
 
Old August 2nd, 2010, 11:49 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You misunderstood. a HyperLink simply ends up as a <a href /> element in the browser. By linking it to the same page, with HidePanel=True in the query string you can reload the page and hide the panel. However, indeed you probably want a LinkButton. It also ends up as an <a href /> but uses JavaScript to post back to the same page.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 10th, 2010, 10:08 AM
Authorized User
 
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello again,

I inserted a LinkButton in my page with a PostBackUrl;

Code:
<asp:LinkButton ID="LinkButton" runat="server" PostBackUrl="SomePage.aspx">Link</asp:LinkButton>
Then in my CodeBehind i wrote;

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Panel.Visible = False

If LinkButton.OnClientClick Then
    Panel.Visible = True
End If
With this I get an error message saying the "in-data-string had an incorrect format". What do I need to do, or did I write the wrong script?

Cheers
Peter
 
Old August 10th, 2010, 10:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're mixing up lots of stuff.

First, remove the PostBackUrl property. Then double click the LinkButton in design view to set up a *server side* Click handler. Inside that method, hide the panel.

This all assumes the Panel and LinkButton are in the same page.

OnClientClick is a property that is used to assign a client side JavaScript function that is triggered when the link button is clicked at the client; e.g. before the post back.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 10th, 2010, 10:36 AM
Authorized User
 
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see now what I did wrong, that worked perfectly!

Though, I am making the Panel visible inside the method, as I want it to be invisible from the start. But either way it works perfectly.

Thanks for the help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Panel in the viewstack not visible Soorej Simon Flex 0 July 16th, 2009 12:40 AM
Hide and make visible scandalous ASP.NET 2.0 Basics 0 May 24th, 2007 08:51 AM
Making a Panel visible in a FormView steve35719 VB How-To 0 June 29th, 2006 07:49 AM
Make visible/invisible stealthdevil Access VBA 6 May 31st, 2006 10:59 AM
Panel.visible shai505 C# 1 April 25th, 2006 05:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.