Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Compilation Error - "CS1513: } expected"

Compilation Error - "CS1513: } expected"

Scheduled Pinned Locked Moved ASP.NET
helpquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blumen
    wrote on last edited by
    #1

    Hi, I always get this error when i use events for controls in aspx, events like onClick(), checkedChanged(), .. If I remove that event from aspx the error disappears, pls find the error details below. I tried giving semi-colon after the function name like: OnClick="NumericOnly_onkeypress(event);" still i get this error. Has anyone come across this error? Reagrds, Blumen

    K 2 Replies Last reply
    0
    • B Blumen

      Hi, I always get this error when i use events for controls in aspx, events like onClick(), checkedChanged(), .. If I remove that event from aspx the error disappears, pls find the error details below. I tried giving semi-colon after the function name like: OnClick="NumericOnly_onkeypress(event);" still i get this error. Has anyone come across this error? Reagrds, Blumen

      K Offline
      K Offline
      kiran kumar Intelligroup
      wrote on last edited by
      #2

      HI Blumen, I am not sure but try like this..

      Kiran Kumar.CH (MCP)

      B 1 Reply Last reply
      0
      • K kiran kumar Intelligroup

        HI Blumen, I am not sure but try like this..

        Kiran Kumar.CH (MCP)

        B Offline
        B Offline
        Blumen
        wrote on last edited by
        #3

        Then I get the error saying that, this aspx does not contain a definition for "NumericOnly_onkeypress". This happens with RadioButton and CheckBox also, when i use its CheckedCHanged event

        1 Reply Last reply
        0
        • B Blumen

          Hi, I always get this error when i use events for controls in aspx, events like onClick(), checkedChanged(), .. If I remove that event from aspx the error disappears, pls find the error details below. I tried giving semi-colon after the function name like: OnClick="NumericOnly_onkeypress(event);" still i get this error. Has anyone come across this error? Reagrds, Blumen

          K Offline
          K Offline
          kiran kumar Intelligroup
          wrote on last edited by
          #4

          Make sure that autoeventwireup at page attribute is turned off i.e make it false if you are using IDE. Make sure that "NumericOnly_onkeypress" event handler has correct arguments i.e void NumericOnly_onkeypress(sender as object,e as EventArgs) { } Tell me where you are writing this handler either in code behind i.e .cs file are inpage i.e in aspx file?

          Kiran Kumar.CH (MCP)

          B 1 Reply Last reply
          0
          • K kiran kumar Intelligroup

            Make sure that autoeventwireup at page attribute is turned off i.e make it false if you are using IDE. Make sure that "NumericOnly_onkeypress" event handler has correct arguments i.e void NumericOnly_onkeypress(sender as object,e as EventArgs) { } Tell me where you are writing this handler either in code behind i.e .cs file are inpage i.e in aspx file?

            Kiran Kumar.CH (MCP)

            B Offline
            B Offline
            Blumen
            wrote on last edited by
            #5

            kiran kumar[Intelligroup] wrote:

            Make sure that autoeventwireup at page attribute is turned off

            It was turned off already, still same error

            kiran kumar[Intelligroup] wrote:

            Tell me where you are writing this handler

            in aspx This is the function: function NumericOnly_onkeypress() { if(window.event.keyCode<48 || window.event.keyCode>57 ) { window.event.keyCode=false; return false; } } Regards, Blumen

            K B 2 Replies Last reply
            0
            • B Blumen

              kiran kumar[Intelligroup] wrote:

              Make sure that autoeventwireup at page attribute is turned off

              It was turned off already, still same error

              kiran kumar[Intelligroup] wrote:

              Tell me where you are writing this handler

              in aspx This is the function: function NumericOnly_onkeypress() { if(window.event.keyCode<48 || window.event.keyCode>57 ) { window.event.keyCode=false; return false; } } Regards, Blumen

              K Offline
              K Offline
              kiran kumar Intelligroup
              wrote on last edited by
              #6

              if you are using asp.net 1.1 do this way remove onclick="NumericOnly_onkeypress" in aspx file and write the statement like this in .cs file page load event buttion1.attributes.add("onclick","NumericOnly_onkeypress"); if you are using asp.net 2.0 you can write like this Text="Button" önClientClick="NumericOnly_onkeypress">

              Kiran Kumar.CH (MCP)

              B 1 Reply Last reply
              0
              • K kiran kumar Intelligroup

                if you are using asp.net 1.1 do this way remove onclick="NumericOnly_onkeypress" in aspx file and write the statement like this in .cs file page load event buttion1.attributes.add("onclick","NumericOnly_onkeypress"); if you are using asp.net 2.0 you can write like this Text="Button" önClientClick="NumericOnly_onkeypress">

                Kiran Kumar.CH (MCP)

                B Offline
                B Offline
                Blumen
                wrote on last edited by
                #7

                Thanks Kiran, that did the trick for TextBox keypress event, but for Radiobutton and CheckBox, the function in aspx is not firing: I gave it like this: rbn1.Attributes.Add("OnCheckedChanged", "Onkeypress(this)"); rbn2.Attributes.Add("OnCheckedChanged", "Onkeypress(this)"); function Onkeypress(thiss) { if (document.getElementById (thiss.id).checked == true) alert("checked"); } Why does it work when I hook the event handler as an attribute? And why doesn't it work for RadioButton and CheckBox? Regards, Blumen

                K 1 Reply Last reply
                0
                • B Blumen

                  Thanks Kiran, that did the trick for TextBox keypress event, but for Radiobutton and CheckBox, the function in aspx is not firing: I gave it like this: rbn1.Attributes.Add("OnCheckedChanged", "Onkeypress(this)"); rbn2.Attributes.Add("OnCheckedChanged", "Onkeypress(this)"); function Onkeypress(thiss) { if (document.getElementById (thiss.id).checked == true) alert("checked"); } Why does it work when I hook the event handler as an attribute? And why doesn't it work for RadioButton and CheckBox? Regards, Blumen

                  K Offline
                  K Offline
                  kiran kumar Intelligroup
                  wrote on last edited by
                  #8

                  Now it will work because OnCheckedChange is serverside event.but your function is at client side naa so write like this rbn1.Attributes.Add("onclick", "Onkeypress(this)"); rbn2.Attributes.Add("onclick", "Onkeypress(this)");

                  Kiran Kumar.CH (MCP)

                  1 Reply Last reply
                  0
                  • B Blumen

                    kiran kumar[Intelligroup] wrote:

                    Make sure that autoeventwireup at page attribute is turned off

                    It was turned off already, still same error

                    kiran kumar[Intelligroup] wrote:

                    Tell me where you are writing this handler

                    in aspx This is the function: function NumericOnly_onkeypress() { if(window.event.keyCode<48 || window.event.keyCode>57 ) { window.event.keyCode=false; return false; } } Regards, Blumen

                    B Offline
                    B Offline
                    badgrs
                    wrote on last edited by
                    #9

                    You are getting the server-side and client-side events mixed up. For an OnClick is the server side event (and expects a function name that is in your code behind) and OnClientClick is where you can put client-side javascript calls (this attribute simply expects a string). Have a look at the MSDN documentation for more.

                    B 1 Reply Last reply
                    0
                    • B badgrs

                      You are getting the server-side and client-side events mixed up. For an OnClick is the server side event (and expects a function name that is in your code behind) and OnClientClick is where you can put client-side javascript calls (this attribute simply expects a string). Have a look at the MSDN documentation for more.

                      B Offline
                      B Offline
                      Blumen
                      wrote on last edited by
                      #10

                      I couldn't find OnClicntClick for CheckBox and RadioButton, what do we do in that case?

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups