 |
| 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
|
|
|
|

August 1st, 2010, 01:19 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 1st, 2010, 03:45 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 2nd, 2010, 11:42 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 2nd, 2010, 11:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 10th, 2010, 10:08 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 10th, 2010, 10:16 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 10th, 2010, 10:36 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|
 |