Errors.  Urgent need to turn in homework Expert gone to sleep!

assaultkitty
assaultkitty used Ask the Experts™
on
Need help with this default.aspx.cs  I have the following errors.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace HitCounter
{
   public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {  
         HitCounter hitCounter = new HitCounter();
            // Sets the property.
            hitCounter.MyTotalNumberofHits = 5;
           
            // Gets the property.
            lblTotalNumberofHits.Text = hitCounter.MyTotalNumberofHits.ToString();

            if (!IsPostBack)
            {        
                public int getTotalNumberofHits()
                {
                    SqlConnection sqlConnection1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename='C:\\Course Technology\\CIS Programming\\ASP .NET Programming\\Data Files\\Chapter.10\\Chapter\\HitCounter\\HitCounter\\App_Data\\HitCounterDatabase.mdf'; Integrated Security=true; User Instance=true");
                    SqlCommand cmd = new SqlCommand();
                    int totalNumberofHits;

                    cmd.CommandText = "SELECT COUNT(*)FROM Counter";
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = sqlConnection1;

                    sqlConnection1.Open();

                    totalNumberofHits = (int)cmd.ExecuteScalar();

                    sqlConnection1.Close();

                    return totalNumberofHits; //return the integer
       
            }   }
             
 }
}
}

Error      1      } expected      C:\Course Technology\CIS Programming\ASP .NET Programming\Data Files\Chapter.10\Chapter\HitCounter\HitCounter\Default.aspx.cs      24      14      HitCounter

Error      2      Type or namespace definition, or end-of-file expected      C:\Course Technology\CIS Programming\ASP .NET Programming\Data Files\Chapter.10\Chapter\HitCounter\HitCounter\Default.aspx.cs      46      1      HitCounter


Error      3      Type or namespace definition, or end-of-file expected      C:\Course Technology\CIS Programming\ASP .NET Programming\Data Files\Chapter.10\Chapter\HitCounter\HitCounter\Default.aspx.cs      46      1      HitCounter
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you cannot have a function in another function:-
I just hope that you have HitCounter class in your solution somewhere.
If it is not, simply assign value 5 to your label using this:-0

lblTotalNumberofHits.Text="5";

if (!IsPostBack)
            {        
                    SqlConnection sqlConnection1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename='C:\\Course Technology\\CIS Programming\\ASP .NET Programming\\Data Files\\Chapter.10\\Chapter\\HitCounter\\HitCounter\\App_Data\\HitCounterDatabase.mdf'; Integrated Security=true; User Instance=true");
                    SqlCommand cmd = new SqlCommand();
                    int totalNumberofHits;

                    cmd.CommandText = "SELECT COUNT(*)FROM Counter";
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection = sqlConnection1;

                    sqlConnection1.Open();

                    totalNumberofHits = (int)cmd.ExecuteScalar();

                    sqlConnection1.Close();

                    //return totalNumberofHits; //return the integer
       
            }   

Open in new window

Senior Software Engineer
Top Expert 2009
Commented:
Just to clarify the previous comment:
If HitCounter class is not defined, modify Page_Load as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
    lblTotalNumberofHits.Text="5";
}

Build and run your page and see that label is set to 5

After you add the HitCounter class to your solution:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) // I am assuming you are trying to set this value only when page is loaded the first time.
{
            HitCounter hitCounter = new HitCounter();
            // Sets the property.
            hitCounter.MyTotalNumberofHits = 5;
            // Gets the property.
            lblTotalNumberofHits.Text = hitCounter.MyTotalNumberofHits.ToString();
}
}
Note: There is no need for the getTotalNumberofHits method as it is not called anywhere in your code.
The key idea in writing code is to add/modify a bit a t the time so that you have more confidence in your code. If you have played Lego before, you build things one block at the time.
Good luck.
Top Expert 2015

Commented:
Experts,

There's so much more to this question than meets the eye. There is a HitCounter class.

Have a look here:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27676536.html

Author

Commented:
thank you.

Author

Commented:
Moderator.  If you look back at the notes, I had a deadline of 12 PM on Sunday night.  The expert did not give me any answer to the question.  I got this answer more than three hours and I was late.  I did not answer the question at all.  It just gave me an idea on how this program was suppose to look.  The answer the expert is not the answer to the program.  I think you acting before you understand what is going here.  Please give the expert back his points.  I can download the program that I turned in to the professor and it does not look like that. The program only puts a bracket where it needed be placed.

Author

Commented:
This is my work.  Compare it to the experts.  You are wrong.  I want to speak with your boss.
Default.aspx.cs
HitCounter.cs

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial