Easy way to get index page from php to asp
I have done it in php and is now trying to do the same in asp.net. In php I've done something like this
HTML Code:
<html>
<body>
<?php
if( $_GET['page'] == "index" )
include('home.php')
else if( $_GET['page'] == "login" )
include('login.php');
Can you try and teach me some asp.net (with c#). Should I add the code in the aspx or aspx.cs for index.aspx page? And what should the code be?
Re: Easy way to get index page from php to asp
I have searched for your problem on Google and it gave me the following:
HTML Code:
Request.QueryString["page"]
Request.QueryString["page"] will get the page url parameter. Request.Form["variable"] will give you the POST fields. Includes exist in ASP.NET, but only for compatibility with classic ASP. But I would recommend you to create a User Controls instead. And always remember that it is always good to have a program against controls and then generate HTML.
Re: Easy way to get index page from php to asp
I know all this things. However the url looks something like this: .. /index.aspx?page=login. WHAT and WHERE in the code do I test? I have the following in my index page, in the body:
Code:
<%
if( Request.QueryString["page"] != null )
{
if (Request.QueryString["page"].Equals("login"))
Response.Write("LOGIN PAGE");
}
else
Response.Write("MAIN PAGE");
%>
But I'm stuck on what to do to include the correct pages. After some searching, guessing and results I have come up with something. But wonder if this is the best way to do it. I have then in advance about 2 "Web User Controls", login and main. login.ascx. Anybody have any objections? Is this incorrect use of the Web User Controls to what I'm trying to achieve (.. /index.aspx?page=abc).
Re: Easy way to get index page from php to asp
No it's certainly not a good way to do it. If you really want to do something similar to this in ASP.NET, you can look at Master Pages. Does not really understand why you want to do it this way other than proper url. But if you absolutely have to, then you can just run something like this...
Reading QueryString
Open the file that points to the QS with a normal System.IO function.
Perform file out again with Response.Write
Re: Easy way to get index page from php to asp
Previously I was using VB.NET but when I write ASP.NET pages this is how it is done that does the same operation.
Code:
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server">
Sub _onload(sender as Object, e as System.EventArgs) Handles Me.Load
Dim page As String = Request.QueryString("page")
Select Case page.ToLower
Case "login"
myContent.Controls.Add(LoadControl("./ControlFolder/Login.ascx"))
Case Else
myContent.Controls.Add(LoadControl("./ControlFolder/Main.ascx"))
End Select
End Sub
</script>
<head>
<title></title>
</head>
<body>
<div id="myContent" runat="server"></div>
</body>
</html>