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. Problem calling javascript function from codebehind( asp.net..)

Problem calling javascript function from codebehind( asp.net..)

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascriptasp-net
10 Posts 4 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.
  • R Offline
    R Offline
    Rahul Chitte
    wrote on last edited by
    #1

    I m not able to call javascript function ValidateYear with year as parameter, can some1 help reg this issue, i hv written following code in aspx code behind.. Dim sbScript As New System.Text.StringBuilder             sbScript.Append("ValidateYear(")             sbScript.Append(cboYearAtCurrentAddressCoApplicantContact.Text)             sbScript.Append(");")             'Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "key",sbScript.ToString, False)             ClientScript.RegisterClientScriptBlock(Page.GetType, "key", sbScript.ToString, False) Neither exception is thrown nor calling javascript.Plz Help

    C A A 3 Replies Last reply
    0
    • R Rahul Chitte

      I m not able to call javascript function ValidateYear with year as parameter, can some1 help reg this issue, i hv written following code in aspx code behind.. Dim sbScript As New System.Text.StringBuilder             sbScript.Append("ValidateYear(")             sbScript.Append(cboYearAtCurrentAddressCoApplicantContact.Text)             sbScript.Append(");")             'Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "key",sbScript.ToString, False)             ClientScript.RegisterClientScriptBlock(Page.GetType, "key", sbScript.ToString, False) Neither exception is thrown nor calling javascript.Plz Help

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Well, it seems you don't put quotes around the text you're emitting. Beyond that, why you'd do a postback and then run a js function, what it does, and what you mean by 'problem' ( that is, what happens, and what you expect to happen ) are mysteries, so it's impossible to offer more help.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • R Rahul Chitte

        I m not able to call javascript function ValidateYear with year as parameter, can some1 help reg this issue, i hv written following code in aspx code behind.. Dim sbScript As New System.Text.StringBuilder             sbScript.Append("ValidateYear(")             sbScript.Append(cboYearAtCurrentAddressCoApplicantContact.Text)             sbScript.Append(");")             'Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "key",sbScript.ToString, False)             ClientScript.RegisterClientScriptBlock(Page.GetType, "key", sbScript.ToString, False) Neither exception is thrown nor calling javascript.Plz Help

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        Do you have AJAX ScriptManager in your page ?

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

        C R 2 Replies Last reply
        0
        • A Abhijit Jana

          Do you have AJAX ScriptManager in your page ?

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Why would he have to ? Nothing in his post has anything to do with AJAX.

          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

          A 1 Reply Last reply
          0
          • R Rahul Chitte

            I m not able to call javascript function ValidateYear with year as parameter, can some1 help reg this issue, i hv written following code in aspx code behind.. Dim sbScript As New System.Text.StringBuilder             sbScript.Append("ValidateYear(")             sbScript.Append(cboYearAtCurrentAddressCoApplicantContact.Text)             sbScript.Append(");")             'Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "key",sbScript.ToString, False)             ClientScript.RegisterClientScriptBlock(Page.GetType, "key", sbScript.ToString, False) Neither exception is thrown nor calling javascript.Plz Help

            A Offline
            A Offline
            Arun Jacob
            wrote on last edited by
            #5

            If you are trying to validate a textbox its better to add attributes to the textbox instead of using script block.Just like, txtName.attributes.Add("onchange","return FunctionName('"+ parameter +"')");

            Arun Jacob http://codepronet.blogspot.com/

            R 1 Reply Last reply
            0
            • A Arun Jacob

              If you are trying to validate a textbox its better to add attributes to the textbox instead of using script block.Just like, txtName.attributes.Add("onchange","return FunctionName('"+ parameter +"')");

              Arun Jacob http://codepronet.blogspot.com/

              R Offline
              R Offline
              Rahul Chitte
              wrote on last edited by
              #6

              You are perfectly right but i have to explicitly call that function from one of my checkbox event based on some condition. The scenario is as below : I am assigning text of dropdown1 to another dropdown2 , i have written javascript function for its   onchange event and based on dropdown2 text i am hiding section below dropdown2 using javascript, the thing is that when i m changing value from dropdown2 then it is working fine but when i m trying to assign value of dropdown1 to dropdown2 using .Text property the section below is not getting hide because onchange event is not getting fired.

              C 1 Reply Last reply
              0
              • R Rahul Chitte

                You are perfectly right but i have to explicitly call that function from one of my checkbox event based on some condition. The scenario is as below : I am assigning text of dropdown1 to another dropdown2 , i have written javascript function for its   onchange event and based on dropdown2 text i am hiding section below dropdown2 using javascript, the thing is that when i m changing value from dropdown2 then it is working fine but when i m trying to assign value of dropdown1 to dropdown2 using .Text property the section below is not getting hide because onchange event is not getting fired.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                So why are you doing a postback and why, if you're already running your own js code, don't you just add code to hide it ?

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                1 Reply Last reply
                0
                • C Christian Graus

                  Why would he have to ? Nothing in his post has anything to do with AJAX.

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  A Offline
                  A Offline
                  Abhijit Jana
                  wrote on last edited by
                  #8

                  No, I have just asked because if there is ScriptManager on his page, then he can try with ScriptManager.RegisterStartupScript().

                  Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                  C 1 Reply Last reply
                  0
                  • A Abhijit Jana

                    No, I have just asked because if there is ScriptManager on his page, then he can try with ScriptManager.RegisterStartupScript().

                    Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    His basic issue is probably that he's not putting quotes around a constant string. If the code he's using is not working, then ScriptManager is not going to help, it does the same thing.

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    1 Reply Last reply
                    0
                    • A Abhijit Jana

                      Do you have AJAX ScriptManager in your page ?

                      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                      R Offline
                      R Offline
                      Rahul Chitte
                      wrote on last edited by
                      #10

                      Yes i do have ScriptManager on my page

                      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