CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > visual_studio.visual_studio_2005 Tags:
Item Type: Date Entered: 7/8/2005 1:38:35 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 6 Views: 23 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
"Addict" <>
NewsGroup User
Basic Q's - Query Strings, includes, etc7/8/2005 1:38:35 PM

0

Previously I've been using PHP to do all my web sites.  Now I've been tasked with ASP.NET at work (since I already have a .NET background).  I need some help figuring out how things work in ASP.NET.  I'm using Visual Studio .NET 2005 Beta 2.

In PHP, I could parse a query string and determine which content to display.  For example, from the url http://www.example.com/index.php?page=news, I could see that the user wanted the news section and include news.php within index.php.

Sample PHP Code:

<?php
switch ($page) {
case 'news':
include ('includes/news.php');
break;
   
default:
include ('includes/home.php');
}
?>


Pretty easy.  The index.php could contain some basic HTML for structure.  The included file would contain the neccessary code to produce the desired output (i.e. - code to get articles from a db).

So how could I accomplish this in ASP.NET?  The structure of things is completely different (or at least it seems that way to me).  Is there a better way than including the files?  Maybe controls of some sort?

I am attempting to use Master Pages for consistent look & feel (pretty cool feature) as well.


www.DigitalDeviation.com
"ByReckon" <>
NewsGroup User
Re: Basic Q's - Query Strings, includes, etc7/8/2005 2:26:06 PM

0

Hello,

I can't help you too much because I don't know at all how PHP works, but
here you can find help about some difference between both.

Regards.

VB .Net Coder - Apologize my C# nescience
Best Regards.
"Luis Abreu" <>
NewsGroup User
Re: Basic Q's - Query Strings, includes, etc7/8/2005 2:37:58 PM

0

Hello.

it seems like you're tryiong to access the query string variable defined in the url. if that's the case, then you have several options. for instance, you can use the QueryString collection property exposed by the HttpRequest class (exposed by the Page class through the Request property). btw, you can also get a valid reference to the request obejct through the Request property exposed by the HttpContext class.

after getting the varaibles you can do several things with it: for instance, you can load a user control that is put on a placeholder on the the page. what you have to keep in mind is that that kind of code (as the one you've shown) is gone: everything is object oriented now :D


--
Regards,
Luis Abreu
email: labreu_at_gmail.com
PT blog: http://weblogs.pontonetpt.com/luisabreu
EN blog:http://msmvps.com/blogs/luisabreu
http://www.pontonetpt.com
http://weblogs.pontonetpt.com/
"Addict" <>
NewsGroup User
Re: Basic Q's - Query Strings, includes, etc7/8/2005 2:45:49 PM

0

Well I understand how to obtain the query string (Request.QueryString) so I've gotten that far.Smile [:)]

Hmm.  I guess what I need to look into is user controls.  Any good references for user controls in ASP.NET?  I started to look along that path, but I wasn't sure if that was the way I should do it.


Thanks for the replies!


www.DigitalDeviation.com
"Fredrik K" <>
NewsGroup User
Re: Basic Q's - Query Strings, includes, etc7/11/2005 10:03:13 AM

0

I think you're on the right track with respect to using user controls, at least for what you want. I'd argue that maybe it'd be better to have a separate news.aspx , article.aspx etc page that inherits the masterpage and just use a standard hyperlink to navigate, but I guess it boils down to preference :)

What you could do, is place a set of user controls on the page, set them all to visible = false, and then depending on what the querystring value is set the appropriate controls to visible = true within an if(!IsPostBack) in the Page_Load event.

Have a look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconwebformsusercontrols.asp for more on user controls.

Good luck!


Blog: http://blog.iridescence.no
"Addict" <>
NewsGroup User
Re: Basic Q's - Query Strings, includes, etc7/11/2005 11:53:31 AM

0

 Fredrik K wrote:
What you could do, is place a set of user controls on the page, set them all to visible = false, and then depending on what the querystring value is set the appropriate controls to visible = true within an if(!IsPostBack) in the Page_Load event.

Wouldn't that consume more resources though?  In effect the controls would still be loaded each time right?
www.DigitalDeviation.com
"Addict" <>
NewsGroup User
Re: Basic Q's - Query Strings, includes, etc7/11/2005 2:01:08 PM

0

Here's how I've decided to handle things.  Small little snippet from my Default.aspx page.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Select Case Request.QueryString("page")
Case "news"
Me.phMain.Controls.Add(LoadControl("controls/news.ascx"))
Case "login"
Me.phMain.Controls.Add(LoadControl("controls/login.ascx"))
Case "links"
Me.phMain.Controls.Add(LoadControl("controls/links.ascx"))
Case Else
Me.phMain.Controls.Add(LoadControl("controls/home.ascx"))
End Select
End Sub


phMain is a placeholder in Default.aspx.  The query string would look like Default.aspx?page=links.  Pretty basic for now.

Just in case any other newbies stumble across this.Smile [:)]


www.DigitalDeviation.com
7 Items, 1 Pages 1 |< << Go >> >|




   
  Privacy | Contact Us
All Times Are GMT