Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 July 9th, 2003, 02:51 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP .NET using C# problem !!

Hi,

I got the following code:


<script runat="server" language="c#">
void Page_Load()
{
if (Request.Form["list1"] != "")
{
message.Text = "You have selected " + Request.Form["list1"];
}
}
</script>
<html>
<head>
<title>Drop Down List Example</title>
</head>
<body>
<asp:label id="message" runat="server"/>
<br />
<form runat="server">
Which city do you wish to look at hotels for?<br /><br />
<asp:listbox id="list1" runat="server" selectionmode="multiple">
<asp:listitem>Madrid</asp:listitem>
<asp:listitem>Oslo</asp:listitem>
<asp:listitem>Lisbon</asp:listitem>
</asp:listbox>
<br /><br /><br /><br />
<input type="Submit">
</form>
</body>
</html>



When the 1st time I ran this page in IE 6.0 by entering 127.0.0.1/ch01/listpage.aspx

The message label shouldn't come out with the phrase "You have selected " since I have prevented it from appearing using the asp script with the if statement. But it still display when I 1st load the page.
Pls...................help......................!!
 
Old July 9th, 2003, 09:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

If you want to prevent the label's text from appearing you can use IsPostBack page's property. That means that the code piece will be run only if the form has submitted.
Code:
void Page_Load()
{
    if (IsPostBack)
    {
        if (Request.Form["list1"] != "") 
        {
            message.Text = "You have selected " + Request.Form["list1"];
        }
    }
}
Regs,
NNJ

...but the Soon is eclipsed by the Moon
 
Old July 9th, 2003, 10:40 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot NotNowJohn ! It's working now !
 
Old July 9th, 2003, 09:54 PM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

  If I changed the asp script to below:

  void Page_Load()
  {
if (IsPostBack)
{
     if (Request.Form["list1"] != "")
        message.Text = "You have selected " + Request.Form["list1"];
     else
        message.Text = "You have selected nothing";
    }
  }

  and select nothing from the listbox, the label(message) should display "You have selected nothing". Why is that it still display "You have selected " ??

R there a lot of bugs inside Wrox book?
Quote:
quote:Originally posted by NotNowJohn
 If you want to prevent the label's text from appearing you can use IsPostBack page's property. That means that the code piece will be run only if the form has submitted.
Code:
void Page_Load()
{
    if (IsPostBack)
    {
        if (Request.Form["list1"] != "") 
        {
            message.Text = "You have selected " + Request.Form["list1"];
        }
    }
}
Regs,
NNJ

...but the Soon is eclipsed by the Moon
 
Old July 10th, 2003, 10:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

You don't have to use Request.Form collection in order to restore the value of listbox. In ASPX pages u can use the variable list1 instead of Request.Form["list1"];
For the appropriate message u can use following code:
Code:
 if (list1.SelectedIndex!=-1) 
        message.Text = "You have selected " + list1.SelectedItem.Text;
     else
        message.Text = "You have selected nothing";


...but the Soon is eclipsed by the Moon
 
Old July 11th, 2003, 09:33 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thks a lot John !





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom HTTP 404 Problem w/ASP to ASP.NET kwilliams ASP.NET 2.0 Professional 7 November 26th, 2007 04:17 PM
Problem Converting C# to VB.NET in ASP.NET kwilliams ASP.NET 2.0 Basics 0 February 9th, 2007 06:22 PM
asp.net problem [email protected] Visual Studio 2005 1 January 22nd, 2007 10:49 AM
Problem with Exercise in Beg. asp.net for VB.net! mrfella71 BOOK: Beginning ASP.NET 1.0 1 October 23rd, 2005 12:06 PM





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