Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

error CS1513: } expected, and error CS1022: Type or namespace definition

namespace

  • Please log in to reply
5 replies to this topic

#1 surreal5335

surreal5335

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 19 June 2010 - 07:50 PM

I am working on my first c# program, done a number of other languages before, just new to this one.
I am recieving the following errors:

error CS1513: } expected
error CS1022: Type or namespace definition, or end-of-file expected


Seem straight forward, but for the life of me I cant see the problem. There is a matching brace for the opening one. Seems these two errors go hand in hand from what I have read.

Microsft mentions about volatile variables can cause this, but I dont use any of those. Mentions moving the #endregion directive'}'. I did and no-surprise, it didnt change anything.

Here is my code:

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


namespace Hultin
{
    public partial class _orderform : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        { [COLOR="Red"]// error CS1513: } expected[/COLOR]

            void annoyDropDown() {

                if (!IsPostBack) {

                   ArrayList values = new ArrayList();

                   values.Add ("not really");
                   values.Add ("kind of");
                   values.Add ("really");
                   values.Add ("extremely");
               

                   AnnoyDropDown.DataSource = values;
                   AnnoyDropDown.DataBind();
                } // end if () {

                } // end annoyDropDown

                void SubmitBtn_Click(Object sender, EventArgs e) {
                   Label1.Text = "This form started to : " + AnnoyDropDown.SelectedItem.Text + " annoy you.";
                } // end annoy drop down list
    


        void surveyDropDown () {

        if (!IsPostBack) {

               ArrayList values = new ArrayList();

               values.Add ("oh yes!");
               values.Add ("is there any prizes?");
               values.Add ("no thanks");
               values.Add ("are you kidding!?");
               

               SurveyDropDown.DataSource = values;
               SurveyDropDown.DataBind();
            }
        
        } // end surveyDropDown ()

        void SubmitBtn_Click(Object sender, EventArgs e) {
           Label2.Text = "When asked if you wanted to take a survey, you responded with: " + SurveyDropDown.SelectedItem.Text + " annoy you.";
        } // end survey drop down list



        }
    }
} [COLOR="Red"]// error CS1022: Type or namespace definition[/COLOR]

I appreciate the help
  • 0

#2 Davide

Davide

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 484 posts

Posted 20 June 2010 - 01:03 AM

Try to remove "partial" class and tell me if it works.
  • 0
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#3 surreal5335

surreal5335

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 20 June 2010 - 08:21 AM

Thanks for the reply, I removed "partial" from the class definition, but the error remains. I have also heard VS sometimes requires a complete restart to fully recognize a bug fix. I have restarted the program a number of times but still the bug remains.

I appreciate the help and any other ideas you may have
  • 0

#4 abzero

abzero

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 205 posts

Posted 20 June 2010 - 12:38 PM

Thanks for the reply, I removed "partial" from the class definition, but the error remains. I have also heard VS sometimes requires a complete restart to fully recognize a bug fix. I have restarted the program a number of times but still the bug remains.

I appreciate the help and any other ideas you may have


Any reason you declared all the functions inside:

protected void Page_Load(object sender, EventArgs e)
        { // error CS1513: } expected


It's probably complaining that it expects that function to be closed before the others are defined, and hence the } expected.
  • 0

#5 Davide

Davide

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 484 posts

Posted 20 June 2010 - 08:58 PM

Any reason you declared all the functions inside:

protected void Page_Load(object sender, EventArgs e)
        { // error CS1513: } expected


It's probably complaining that it expects that function to be closed before the others are defined, and hence the } expected.


Yeah, your right. It's hard to notice when there is no syntax highlighting.
  • 0
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#6 surreal5335

surreal5335

    CC Lurker

  • Just Joined
  • Pip
  • 3 posts

Posted 20 June 2010 - 09:52 PM

Thanks for the reply. I figured out that page_load() {} must be done before any functions are defined. So that fixed that error. Now all my variables arent being recognized.

My current code is:

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



    public class _orderform : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                ArrayList values = new ArrayList();

                values.Add("not really");
                values.Add("kind of");
                values.Add("really");
                values.Add("extremely");

                AnnoyDropDown.DataSource = values;
                AnnoyDropDown.DataBind();
            }

            if (!IsPostBack)
            {

                ArrayList values = new ArrayList();

                values.Add("oh yes!");
                values.Add("is there any prizes?");
                values.Add("no thanks");
                values.Add("are you kidding!?");


                SurveyDropDown.DataSource = values;
                SurveyDropDown.DataBind();
            }

        } // end Page_Load()


        

       void chkLayout_CheckedChanged(Object sender, EventArgs e) {
       
          if (chkLayout.Checked == true) {
             newsLetterChoose.RepeatLayout = RepeatLayout.Table;

          } else {
             newsLetterChoose.RepeatLayout = RepeatLayout.Flow;
          } // end if else ()    
       } // end chkLayout_CheckedChanged()
       
       void chkDirection_CheckedChanged(Object sender, EventArgs e) {
       
          if (chkDirection.Checked == true) {
             newsLetterChoose.RepeatDirection = RepeatDirection.Horizontal;
          } else {
             newsLetterChoose.RepeatDirection = RepeatDirection.Vertical;
          }  
       } // end chkDirection_CheckedChanged()



        void submitButton(object Source, EventArgs e) {
          if (newsLetterChoose.SelectedIndex > -1) {  
             letter.Text = "You selected: " + newsLetterChoose.SelectedItem.Text;
          }
            annoy.Text = "This form started to : " + AnnoyDropDown.SelectedItem.Text + " annoy you.";
            survey.Text = "When asked if you wanted to take a survey, you responded with: " + SurveyDropDown.SelectedItem.Text + " annoy you.";
            firstNameCS.Text = "Thank you : " + firstName.Text;
            lastNameCS.Text = lastName.Text;

       } // end submitButton()    

    } // end class _orderform




I appreciate the help

Edited by surreal5335, 20 June 2010 - 10:17 PM.
fixed bug

  • 0





Also tagged with one or more of these keywords: namespace

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download