473,513 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Querystring Check

Hi all,

I am new to asp so bear with me. I want to write a page which will
load a default page for me with some links and all. lets say someone
clicks on the link, which not only points to the same page but also
passes a querystring. Looking at the querystring I will then display
data from a database.
So my question in short is... Is it possible to have a single asp page
which can return either a default page where no querystring is passed
or a result from the database when a querystring is passed?
If the answer is yes, then is it a good idea to do this or have 2
seperate pages?

Thanks
Jul 19 '05 #1
1 2786
Yep - possible. It's quite common to see both methods used. If you're going
to bung everything in the one page then plan it first - map your workflow
using a state transition chart for anything but the most trivial sites. It's
really easy to find examples of where this approach has been used and the
different page views are just implemented using in-line conditional
statements - makes for very hard-to-read code.

The problem with using multiple physical pages is that it's common to see
variables persisted in the querystring or form as you move from page to
page. This makes your data a bit more visible (esp. if using the QS). To
overcome this you can whack it into the Session or a database instead. The
Session requires some thought due to users' use of the Back and Forward
browser buttons, and persisting to a database can complicate your code and
your database structure. Each method has unique advantages and
disadvantages.

If you're going to use the single-page method then think of each page-view
as a state, and the act of clicking a button (etc.) as an event. A common
approach is to pass a value representing each of these two things from 'page
to page' (only one page), detect the state, detect the event and then
display the page accordingly. Each form's processor is at the start of the
next page so you can normally get away with posting from one page to the
other keeping your data out of the QS - i.e. the form submits to itself.
Retrieving the state and event may require use of the QS and/or form
depending on what your events are.

In the code below notice the call to SaveFormData. Make sure you put all of
your logic into functions and subs. There is nothing worse than trying to
debug 1000 lines of someone else's spaghetti when they have used one ASP to
render multiple page views.

Untested code follows. Have a go.

Dim State
Dim Event

State = Request.Form ("S") ' Will be previous page's state.

Select Case State

Case STATE_ENTERNAME

' Our events are our two button clicks. Decode and store the event
first just to keep things tidy.
' Could put the code in these conditionals if you like.
If (Request.Form("cmdSubmitSave") <> "") Then
' Save button clicked.
Event = EV_SAVEDATA
ElseIf (Request.Form("cmdSubmitBack") <> "") Then
' Back button clicked.
Event = EV_BACKTOPREV
End If

' Now take action.
Select Case Event

Case EV_SAVEDATA
' Retrieve and save form data.
SaveFormData ...

Case EV_BACK_TO_PREV
' Redirect to the previous page in the workflow.
Response.Redirect ....

Case Else
' Came from the STATE_ENTERNAME state without an event.
Error condition??

End Select

Case STATE_ENTERSHIPPINGTO

' You get the idea.

Case Else

' Default form view. This is the case that's executed by default.
' It could also be used to handle error conditions.

End Select
Alan

"Deepiceman" <de********@yahoo.com> wrote in message
news:f0*************************@posting.google.co m...
Hi all,

I am new to asp so bear with me. I want to write a page which will
load a default page for me with some links and all. lets say someone
clicks on the link, which not only points to the same page but also
passes a querystring. Looking at the querystring I will then display
data from a database.
So my question in short is... Is it possible to have a single asp page
which can return either a default page where no querystring is passed
or a result from the database when a querystring is passed?
If the answer is yes, then is it a good idea to do this or have 2
seperate pages?

Thanks

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2983
by: Robb Meade | last post by:
Hi all, A recent project that I had finished and went live with no apparant problems. My client received an email from a user who mentioned that by accident they had been typing (over the querystring I guess), and the url had become default.asp?pageid='asd
4
2635
by: Deepster | last post by:
Hi Guys Here is what I am doing ... Have a page default.asp which looks at the url and checks for querystring's. if there are none passed goes to a function. if there are particular querystrings passed goes to the respective function. Now there can be only 2 valid querystrings that can be passed and only one at a time. How to do i check for...
5
23451
by: Keith | last post by:
What is the easiest way to check if a particular QueryString exists? I want to know if the QueryString was ever passed rather than whether it contains a value or not.
4
1600
by: Steve | last post by:
Hi All, This problem is really annoying me, as I am sure there is a simple solution to it. If I try to read a querystring value in the Page_Load event and that querystring does not exist I get the error: Object reference not set to an instance of an object
4
25339
by: Guoqi Zheng | last post by:
On my application, I need to have different action based on the pass in query string. When the query string is not presented, I try to use If request.querystring("id") ="" THEN ...... This is what I did in trational asp, however if I did abov in ASP.NET, I always got an error of "Object reference not set to an instance of an object. " ...
1
3442
by: C | last post by:
Hi, I have been using VB.Net for the past 2 years and have moved to C# I send a value in the URL to a page. In my called page I do below. int intTest = int.Parse(Request.QueryString);
3
3118
by: Dan Sikorsky | last post by:
How can I get the Querystring passed to the Referring Page from its referrer? I don't want the querystring coming to my current page. I want the querystring that came to the referring page, so that I can check for the existance of a parameter value in that previous querystring.
6
1776
by: Joe | last post by:
Hello All: I have a webform (WebForm1.aspx) that retrieves a value from a database (_formSessionId) the first time that it is posted. After the user filles in the form, he/she clicks a Button server control that ultimately redirects him/her to WebForm2.aspx . I need to persist the value of _formSessionId between the initial post and the...
2
7384
by: Kim | last post by:
How do I get all walues if my querystring is empty? If I have a table with let's say 10 rows/records, (ID 1-10). I then have a recordset with request.querystring("id") and get the record having the id thats shown in the address bar ("..com?id=4" would get the record with the id 4). How do I get all records if the querystring is empty ("..com")...
12
8022
by: Uwe Braunholz | last post by:
Hello, working on a asp.net Website brought me to a strange problem. I want to enable my users to pass a search string via the query string of an url. It works if the user calls the URL like "default.aspx?search=mystring" But as soon as a German umlaut is in the query string it does not handle the char correctly (like...
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.