473,664 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i solve this problem?

Hello,

I have this code:

1) <script runat="server">

2)Sub Page_Load(sende r As Object, e As System.EventArg s)
3)Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
4)End Sub

</script>

When I use, for example, page.aspx?searc h=asp%20book everything works
well.
When I call only page.aspx I get this error in line (3):

Object reference not set to an instance of an object.

How can I prevent this?

Thanks,
Miguel

Nov 19 '05 #1
9 1428
"Miguel Dias Moura" <md*REMOVE*mour a@*NOSPAM*gmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

I have this code:

1) <script runat="server">

2)Sub Page_Load(sende r As Object, e As System.EventArg s)
3)Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
4)End Sub

</script>

When I use, for example, page.aspx?searc h=asp%20book everything works
well.
When I call only page.aspx I get this error in line (3):

Object reference not set to an instance of an object.

How can I prevent this?


If Request.QuerySt ring.Length > 0 Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
End If
Nov 19 '05 #2
Hi, Miguel.

Try wrapping your code in an If...Then

<script runat="server">
Sub Page_Load(sende r As Object, e As System.EventArg s)
If Request.QuerySt ring.Count > 0 Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
Else
End If
End Sub
</script>


Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*mour a@*NOSPAM*gmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

I have this code:

1) <script runat="server">

2)Sub Page_Load(sende r As Object, e As System.EventArg s)
3)Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
4)End Sub

</script>

When I use, for example, page.aspx?searc h=asp%20book everything works
well.
When I call only page.aspx I get this error in line (3):

Object reference not set to an instance of an object.

How can I prevent this?

Thanks,
Miguel


Nov 19 '05 #3
Hi, Mark.

My VS's IntelliSense doesn't have a QueryString.Len gth
property, but it does have a QueryString.Cou nt property.

Could you have been thinking of JavaScript/Java ?

Juan T. Llibre
===========
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
"Miguel Dias Moura" <md*REMOVE*mour a@*NOSPAM*gmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

I have this code:

1) <script runat="server">

2)Sub Page_Load(sende r As Object, e As System.EventArg s)
3)Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
4)End Sub

</script>

When I use, for example, page.aspx?searc h=asp%20book everything works
well.
When I call only page.aspx I get this error in line (3):

Object reference not set to an instance of an object.

How can I prevent this?


If Request.QuerySt ring.Length > 0 Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
End If

Nov 19 '05 #4
Sorry, but that could break too. If someone went to
page.aspx?anyth ingelse=IBrokeY ourPage this would also fail. Try this (this
may contain incorrect syntax for null checking it's been a long time since
I've done any VB)

<script runat="server">
Sub Page_Load(sende r As Object, e As System.EventArg s)
If Request.QuerySt ring("search") is not null Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
Else
End If
End Sub
</script>

"Juan T. Llibre [MVP]" wrote:
Hi, Miguel.

Try wrapping your code in an If...Then

<script runat="server">
Sub Page_Load(sende r As Object, e As System.EventArg s)
If Request.QuerySt ring.Count > 0 Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
Else
End If
End Sub
</script>


Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*mour a@*NOSPAM*gmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hello,

I have this code:

1) <script runat="server">

2)Sub Page_Load(sende r As Object, e As System.EventArg s)
3)Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
4)End Sub

</script>

When I use, for example, page.aspx?searc h=asp%20book everything works
well.
When I call only page.aspx I get this error in line (3):

Object reference not set to an instance of an object.

How can I prevent this?

Thanks,
Miguel


Nov 19 '05 #5
re:
Sorry, but that could break too.
How do you figure that ?

*Anything* in the querystring will trigger a
Request.QuerySt ring.Count > 0

Try your example at my site :
http://asp.net.do/test/request.aspx?...IBrokeYourPage
You'll see that a value is reported.

Then, try this:
http://asp.net.do/test/request.aspx
and you'll see that a null value is reported.


Juan T. Llibre
===========
"Scott Simons" <Scott.Simons.A t.MealMagic.Com .Remove.This> wrote in message
news:FA******** *************** ***********@mic rosoft.com... Sorry, but that could break too. If someone went to
page.aspx?anyth ingelse=IBrokeY ourPage this would also fail. Try this
(this
may contain incorrect syntax for null checking it's been a long time since
I've done any VB)

<script runat="server">
Sub Page_Load(sende r As Object, e As System.EventArg s)
If Request.QuerySt ring("search") is not null Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
Else
End If
End Sub
</script>

"Juan T. Llibre [MVP]" wrote:
Hi, Miguel.

Try wrapping your code in an If...Then

<script runat="server">
Sub Page_Load(sende r As Object, e As System.EventArg s)
If Request.QuerySt ring.Count > 0 Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
Else
End If
End Sub
</script>


Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*mour a@*NOSPAM*gmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> Hello,
>
> I have this code:
>
> 1) <script runat="server">
>
> 2)Sub Page_Load(sende r As Object, e As System.EventArg s)
> 3)Dim keywords() As String =
> Request.QuerySt ring("search"). Split(CChar("") )
> 4)End Sub
>
> </script>
>
> When I use, for example, page.aspx?searc h=asp%20book everything works
> well.
> When I call only page.aspx I get this error in line (3):
>
> Object reference not set to an instance of an object.
>
> How can I prevent this?
>
> Thanks,
> Miguel


Nov 19 '05 #6
To illustrate the point further, I added some code
to loop through the keys and values in the querystring,
and response.write the keys and values:

http://asp.net.do/test/request2.aspx...IBrokeYourPage

Test that any way you want to.

Here's some suggested ways:

http://asp.net.do/test/request2.aspx?
http://asp.net.do/test/request2.aspx?a
http://asp.net.do/test/request2.aspx?a=
http://asp.net.do/test/request2.aspx?a=ab
http://asp.net.do/test/request2.aspx?a=a&b=b&c=cd

If there's *any* value(s) in the querystring, the code runs.
If there isn't any value in the query string, the code runs.

Here's the code running at that page :

request2.aspx:
----------------
<%@ Page Language="VB" %>
<script runat="server">
Public Sub Page_Load(Sende r As System.Object, E As System.EventArg s)
If Request.QuerySt ring.Count > 0 Then
Response.Write( "There's a value<br>")
Else
Response.Write( "Null QueryString <br>")
End If
Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollec tion
coll = Request.QuerySt ring
arr1 = coll.AllKeys
For loop1 = 0 To arr1.GetUpperBo und(0)
Response.Write( "Key: " & Server.HtmlEnco de(arr1(loop1)) & "<br>")
arr2 = coll.GetValues( loop1)
For loop2 = 0 To arr2.GetUpperBo und(0)
Response.Write( "Value " & CStr(loop2) & ": " & Server.HtmlEnco de(arr2(loop2)) & "<br><br>")
Next loop2
Next loop1
End Sub
</script>
<html>
<body>
<form id="Form1" runat="server">
</form>
</body>
</html>
----

Can you test and comment ?

This message was formatted as HTML,
in order to preserve line spacing.

Juan T. Llibre
===========
"Juan T. Llibre [MVP]" <no***********@ nowhere.com> wrote in message
news:Oa******** ******@TK2MSFTN GP12.phx.gbl...
re:
Sorry, but that could break too.


How do you figure that ?

*Anything* in the querystring will trigger a
Request.QuerySt ring.Count > 0

Try your example at my site :
http://asp.net.do/test/request.aspx?...IBrokeYourPage
You'll see that a value is reported.

Then, try this:
http://asp.net.do/test/request.aspx
and you'll see that a null value is reported.


Juan T. Llibre
===========
"Scott Simons" <Scott.Simons.A t.MealMagic.Com .Remove.This> wrote in
message news:FA******** *************** ***********@mic rosoft.com...
Sorry, but that could break too. If someone went to
page.aspx?anyth ingelse=IBrokeY ourPage this would also fail. Try this
(this
may contain incorrect syntax for null checking it's been a long time
since
I've done any VB)

<script runat="server">
Sub Page_Load(sende r As Object, e As System.EventArg s)
If Request.QuerySt ring("search") is not null Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
Else
End If
End Sub
</script>

"Juan T. Llibre [MVP]" wrote:
Hi, Miguel.

Try wrapping your code in an If...Then

<script runat="server">
Sub Page_Load(sende r As Object, e As System.EventArg s)
If Request.QuerySt ring.Count > 0 Then
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
Else
End If
End Sub
</script>


Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*mour a@*NOSPAM*gmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
> Hello,
>
> I have this code:
>
> 1) <script runat="server">
>
> 2)Sub Page_Load(sende r As Object, e As System.EventArg s)
> 3)Dim keywords() As String =
> Request.QuerySt ring("search"). Split(CChar("") )
> 4)End Sub
>
> </script>
>
> When I use, for example, page.aspx?searc h=asp%20book everything works
> well.
> When I call only page.aspx I get this error in line (3):
>
> Object reference not set to an instance of an object.
>
> How can I prevent this?
>
> Thanks,
> Miguel



Nov 19 '05 #7
He's looking specifically for "search" in his query string. If search
doesn't exist but other values exist in the query string your logic will
trigger a null ref exception, mine won't. Your examples work just fine
because they aren't doing what the original poster wanted.
Nov 19 '05 #8
Oh, OK...

I got a bit carried away there.

In that case, the code you sent in
needs to me modified somewhat:
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
If Request.QuerySt ring("search") Is Nothing Then
Else
Dim keywords() As String = Request.QuerySt ring("search"). Split(CChar("") )
' etc., etc. etc., ( rest of his code... )
End If
End Sub
</script>
<html>
<body>
' something...
</body>
</html>

---

( Null is C# syntax; Nothing = null in VB/VB.NET )

Thanks...

Juan T. Llibre
===========
"Scott Simons" <Scott.Simons.A t.MealMagic.Com .Remove.This> wrote in message
news:33******** *************** ***********@mic rosoft.com...
He's looking specifically for "search" in his query string. If search
doesn't exist but other values exist in the query string your logic will
trigger a null ref exception, mine won't. Your examples work just fine
because they aren't doing what the original poster wanted.


Nov 19 '05 #9
Thank You Very Much for your help.

Cheers,
Miguel

"Juan T. Llibre [MVP]" <no***********@ nowhere.com> wrote in message
news:no******** ***@nowhere.com :
Oh, OK...

I got a bit carried away there.

In that case, the code you sent in
needs to me modified somewhat:
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
If Request.QuerySt ring("search") Is Nothing Then
Else
Dim keywords() As String =
Request.QuerySt ring("search"). Split(CChar("") )
' etc., etc. etc., ( rest of his code... )
End If
End Sub
</script>
<html>
<body>
' something...
</body>
</html>

---

( Null is C# syntax; Nothing = null in VB/VB.NET )

Thanks...

Juan T. Llibre
===========
"Scott Simons" <Scott.Simons.A t.MealMagic.Com .Remove.This> wrote in
message
news:33******** *************** ***********@mic rosoft.com...
He's looking specifically for "search" in his query string. If
search
doesn't exist but other values exist in the query string your logic
will
trigger a null ref exception, mine won't. Your examples work just
fine
because they aren't doing what the original poster wanted.


Nov 19 '05 #10

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

Similar topics

1
12787
by: BVM | last post by:
Hi, All: I have this error. It seems execution time is too long. Actually the execution time is about 30 seconds(I tested in Query analyzer). How do I solve this problem? System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not...
3
1846
by: Alex | last post by:
Hi, I have a problem involving some design issue. I have two unrelated (that is, they do not derive from the same base) classes: ClassA ClassB Both have a quite similar interface, so they can be use interchangeably, that is: ptr = new ClassA;
7
2002
by: Shapper | last post by:
Hello, I have an ASP:ImageButton where I want to call a function and pass a string: OnClick="Change_Photo("John")" I am having problems with "". I tried
6
2487
by: Federico | last post by:
Hi, this is what I can do: - Create new solutions using VS.Net ASP.Net - Save the solutions, build the solution, view in browser with the solution still open. But, once I close the solution, I can not open it again in VS.Net2003 because it hangs my machine (the whole machine stops responding and there's no alternative but to reboot it!). I can't either browse the created solution because it also hangs the whole machine.
0
1329
by: Jitesh | last post by:
I am facing a problem in webservice, I want to know what will be the exact procedure to solve the problem............. What I want to do............ I have a table named order in SQL Server. There are some fields including OrderID, DomainNameURL, SessionID. I want to create a webservice which takes a parameter(SessionID) and return the details from order table. Here OrderId works as a Unique key. but In some cases when SessionID is not...
27
2296
by: John Salerno | last post by:
Ok, here's a problem I've sort of assigned to myself for fun, but it's turning out to be quite a pain to wrap my mind around. It's from a puzzle game. It will help if you look at this image: http://www.johnjsal.devisland.net/switches.jpg Here's the situation: Each of the four rows in the diagram is considered a single 'panel'. Each panel has eight 'switches', which are composed of two columns each, and these columns have a total of 20...
8
4801
by: vj | last post by:
Hi all, I want to solve the two equations u*tan(u)=w and u^2 + w^2=V^2, where V is a known constant, and u and w are the two unknowns to be determined. Please can someone suggest me how to write a code and solve these equations in C or C++? I am not an expert, but have elementary working knowledge of C.
1
2663
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. I wanted to execute a query which is retrieving the records from table1 by checking the condition for a long long string . I'm using where clause and checking the condition as-
17
4092
by: Michael Reichenbach | last post by:
Here is the example code. int main(int argc, char *argv) { string Result; WIN32_FIND_DATA daten; HANDLE h = FindFirstFile(TEXT("c://test"), &daten); system("PAUSE"); return EXIT_SUCCESS; }
2
2373
by: itsvineeth209 | last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc. U had created table login with fields username(varchar(50)), password(varchar(50)), firstname(varchar(50)), lastname(varchar(50)). U had to display username , first name, last name in default.aspx page after login. One more condition is that, if user fails login...
0
8437
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6187
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.