Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 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
 
Old August 3rd, 2004, 04:03 AM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to avoid error

hi all :
i have use the following code and every thing work good .
except when I don't select any radio option,the error
display.
how to avoid this error?
[u]code:</u>

<script language="vb" runat=server>
  sub page_load()
      if page.ispostback then
          select case(destination.selecteditem.value)
          case "Amman":
               message.text= "You select the jordan capital"
          case "Irbed":
               message.text= "You select the best contry city"
          case "Zarqa":
               message.text= "You select my born city"
          case else:
               message.text= "Select city please"

          end select
      end if
  end sub
</script>

<html>
  <head>
    <title>Case</title>
  </head>

  <body>
    <form runat="server">
      Select your choice of destination:
      <br /><br />
      <asp:RadioButtonList ID="destination" Runat=server>
        <asp:ListItem>Amman</asp:ListItem>
        <asp:ListItem>Irbed</asp:ListItem>
        <asp:ListItem>Zarqa</asp:ListItem>
      </asp:RadioButtonList>
      <br /><br />
      <input type=submit value="Submit Chice">
      <br /><br />
      <asp:Label ID="message" Runat=server/>
    </form>
  </body>
</html>


jordan
 
Old August 3rd, 2004, 07:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What is the error?

 
Old August 3rd, 2004, 08:50 AM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[u]this is the error</u>


Server Error in '/b_case' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 2: sub page_load()
Line 3: if page.ispostback then
Line 4: select case(destination.selecteditem.value)
Line 5: case "Amman":
Line 6: message.text= "You select the jordan capital"


Source File: c:\inetpub\wwwroot\b_case\case.aspx Line: 4

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   ASP.case_aspx.page_load() in c:\inetpub\wwwroot\b_case\case.aspx:4
   System.Web.Util.ArglessEventHandlerDelegateProxy.C allback(Object sender, EventArgs e)
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

jordan
 
Old August 3rd, 2004, 09:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Try adding a Required Field validator to the RadioButtonList.

 
Old August 3rd, 2004, 05:57 PM
Authorized User
 
Join Date: Jul 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Chap,

Another chapter another problem I see! Don't worry I am stuck on chapter 16! but its all fun and games..

I think you just need to move the colon from the else case statement chap, but just incase see below(no pun intended)

Try setting up an If statement that will for instance chack if an option was selected or not,

e.g
<code>

Option 1)

<asp:RadioButtonList ID="destination" Runat=server>
        <asp:ListItem Id="optCapital" Value="Amman"></asp:ListItem>
        <asp:ListItem Id="optBestCity" Value="Irbed"></asp:ListItem>
        <asp:ListItem Id="optMyHome" Value="Zarqa"></asp:ListItem>
      </asp:RadioButtonList>


Option 2)

sub page_load()
      if page.ispostback then
          select case(destination.selecteditem.value)
          case "Amman":
               message.Text= "You select the jordan capital"
          case "Irbed":
               message.Text= "You select the best contry city"
          case "Zarqa":
               message.Text= "You select my born city"
          end select
           else
               message.Text= "Select city please"
      end if

Option 3

Set up a secondary Sub called destinationSelection()
and insert your code into that, then enter the below
into Page_Load Sub.

If Destination.SelectedItem.Value is Nothing then
    Message.Text = "Destination not selected"
        Else
      destinationSelection(Destination)
End If



The.Student

What does my picture not work !
 
Old August 4th, 2004, 01:46 AM
Registered User
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi United Kingdom
thank you for your help but iam sory to tell you that I try all option but nothing change.
if you could please try a code else and tell me.

jordan
 
Old August 4th, 2004, 08:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Maennet,

First, is this an example from the book or just a problem your having with some code your writing? If it's from the book please provide a page number.

Second, is there an object, somewhere, called Message?


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to avoid access denied error satyakishore Javascript 1 March 29th, 2006 01:48 PM
Set Permissions correctly to avoid 80070005 error shogunmike Classic ASP Basics 11 October 25th, 2005 06:50 PM
how to avoid logon justin_min Crystal Reports 0 November 30th, 2004 02:05 PM
Avoid duplicates error screen Varg_88 Access ASP 2 August 3rd, 2004 08:58 AM
Trying to avoid duplicacy aspadda Excel VBA 0 April 23rd, 2004 12:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.