p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Error in Chapter 3 Code or in my head? (http://p2p.wrox.com/showthread.php?t=93439)

JeffPalley August 21st, 2014 09:43 PM

Error in Chapter 3 Code or in my head?
 
I wouldn't write you except that I've been going over this code for three days. It matches every diddle and dot in the book example, but guess what: the panel doesn't appear when the checkbox is checked. (Yes, the checkbox's AutoPostback="true"). It's impossible for me to believe that nonfunctional code would have made it this far without being caught, but I've also gone over and over the code and everything (everything that I understand at least) seems perfect: the Protected Sub CheckBox1_CheckedChanged seems to run, but still ... no panel appears. Normally, I would not bother you with a problem like this, but it's *so* "clearly" the same code as in the book; yet it doesn't run. I'd really appreciate you having a look at it. Thanks, -Jeff

Code:

Container.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Container.aspx.vb" Inherits="Container" %>
<!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">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" Text="Show Panel" />
 
      <asp:Panel ID="Panel1" runat="server" visible="false">
        I am visible now.
      </asp:Panel>

  </div>
  </form>
</body>
</html>

-- Container.aspx.vb --

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Container.aspx.vb" Inherits="Container" %>
<!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">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" Text="Show Panel" />
 
      <asp:Panel ID="Panel1" runat="server" visible="false">
        I am visible now.
      </asp:Panel>

  </div>
  </form>
</body>
</html>


Imar August 24th, 2014 07:03 AM

Hi there,

It looks like you posted the markup twice, instead of the code behind. Can you post the full code for the page again?

Cheers,

Imar

JeffPalley August 25th, 2014 12:17 AM

Yup, I posted the aspx.vb file twice and no aspx. Sorry.
 
Hi again Imar,

There goes my credibility! Well, I guess it comes from staring at the code too long. So here goes again. Starting with Containers.aspx:

Code:



Partial Class Containers
  Inherits System.Web.UI.Page

  Protected Sub CheckBox1_CheckedChanged(sender As Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    Panel1.Visible = True
  End Sub

End Class

You'll notice that I changed the Boolean "Checkbox1.CheckedChanged" to its boiled-down equivalent: "True". Just an attempt to avoid anything that might be behind the problem, and I may have made similar tiny changes in other places. However, in both the standard ("in-your-book) version and in the boiled-down version, that Sub appears to have run, although ineffectively. Also, without thinking I named everything "Container" in the beginning and not "Containers." I changed back to "Containers," but there may be some hidden detritus from the renames that's currently inaccessible to me, given the state of my ignorance about ASP.NET.

Here (again) is the code for Containers.aspx.vb"

Code:



Partial Class Containers
  Inherits System.Web.UI.Page

  Protected Sub CheckBox1_CheckedChanged(sender As Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    Panel1.Visible = True
  End Sub

End Class

I very much appreciate your patience (I didn't used to be a moron), and thanks again,

-Jeff Palley
JeffPalley@gmail.com

P.S. If it helps, I just noticed that if I make the default browser Chrome instead of IE, I get a little bit more when I check the checkbox ("I am visible now" appears, but the panel is still not visible).

Imar August 25th, 2014 07:58 AM

Quote:

I get a little bit more when I check the checkbox ("I am visible now" appears, but the panel is still not visible).
That means it's working. The panel has no visual representation in this exercise, but it shows its contents.

Hope this helps,

Imar

JeffPalley August 25th, 2014 10:08 AM

I sent you the wrong Containers.aspx file
 
... i.e., without the full panel code.

Here's the right Containers.aspx file ...

Code:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Containers.aspx.vb" Inherits="Containers" %>
<!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">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" Text="Show Panel" />
 
      <asp:Panel ID="Panel1" runat="server" visible="False" Width="500px" >
        <asp:Wizard ID="Wizard1" runat="server" Width="500px" ActiveStepIndex="0">
          <WizardSteps>
            <asp:WizardStep runat="server" title="About You" ID="YourName">
              <asp:Label ID="YourNamex" runat="server" Text="Type your name"></asp:Label>
              <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            </asp:WizardStep>
            <asp:WizardStep runat="server" title="Favorite Language">
              <asp:DropDownList ID="FavoriteLanguage" runat="server" AutoPostBack="True">
                <asp:ListItem>Visual Basic</asp:ListItem>
                <asp:ListItem>C#</asp:ListItem>
                <asp:ListItem>CSS</asp:ListItem>
              </asp:DropDownList>
            </asp:WizardStep>
            <asp:WizardStep runat="server" StepType="Complete" Title="Ready">
              Result
            </asp:WizardStep>
          </WizardSteps>
        </asp:Wizard>
      </asp:Panel>

  </div>
  </form>
</body>
</html>

This one works fine (with the default server being Chrome) until I press "Finish" ... at which point it displays a horrible mess of errors that probably makes sense to you, but not to me. I am very sorry that my errors are taking up so much of your time -- but it is highly apreciated.

Thanks,
-Jeff

P.S. Here's the Containers.aspx.vb file that goes with it:

[code]


Partial Class Containers
Inherits System.Web.UI.Page


Dim Result As Object

Protected Sub CheckBox1_CheckedChanged(sender As Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
Panel1.Visible = True
End Sub

Protected Sub Wizard1_FinishButtonClick(sender As Object, e As System.Web.UI.WebControls.WizardNavigationEventArg s) _
Handles Wizard1.FinishButtonClick
Result.Text = "Your name is " & YourName.ID
Result.Text &= "<br />Your favorite language is " & FavoriteLanguage.SelectedValue
End Sub

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

End Sub


End Class

[\code]

Imar August 25th, 2014 10:25 AM

Hi there,

You may want to compare your code with mine, as there are a bunch of errors that will break things pretty badly (as you found out).

1. You renamed the label to YourName, not the TextBox (you also renamed it to YourNamex)

2. In the Complete step you should have a Label control with an ID of Result. Currently, you only have the word Result

3. In your code you're defining a new variable called Result of type Object; that is, you have this code:

Dim Result As Object

You should delete that, as Result should point to the Label from 2.)

4. In the Finish code, you access YourName.ID which returns the control's ID. You want to use YourName.Text instead to get the name the user entered.

There may be other errors but this should get you a long way fixing the issues. Feel free to post your next version of the code in case you keep getting errors.

Cheers,

Imar

JeffPalley August 25th, 2014 11:46 AM

Astonished and humbled
 
Imar,

Thanks for your reply, which lists, in painfully polite detail, the 32,389 errors I made in 25 lines of code. I would tell you how many errors per line that comes to, but at this point I don't even trust myself to do division. You are astonishing, and I can't believe how polite you have been when replying to my CSS (cascading series of stupidities). You will not hear from me again until I reach chapter 10 at least ... my version of self-punishment (sort like abstaining from Imar for Lent).

The summary: you are amazing, and a blessing to the stupid.

Thank you 100 times for your perceptiveness, and thank you 1,000 times for your patient forbearance with me. The only positive thing I can think of (for you, not for me) is that other people's problems will now seem like minor absentmindedness in comparison. Or you can make a game of it: post my list of errors on your wall and throw darts at it: the larger the number you hit, the more points. Ask your friends over for beers and a goot time, but I would appreciate if you could leave my name off the list you post on the wall ... someday I might actually MEET one of your friends, maybe at an airport terminal somewhere, and I'd be embarrassed to watch them falling onto the floor, pointing their finger at me and laughing hysterically.

Have a good week, and may God bless you this week by keeping the idiots away from you for at least the next seven days.

-Jeff

Imar August 25th, 2014 05:12 PM

Haha, don't be too hard on yourself. You bought a beginner's book, didn't you? So isn't it expected to make beginners' mistakes?

Feel free to post follow up questions if you have them, even from chapters 6-9 ;-)

Cheers,

Imar


All times are GMT -4. The time now is 01:57 PM.

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