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. Use of Javascript in ajax enabled Asp.net content pages

Use of Javascript in ajax enabled Asp.net content pages

Scheduled Pinned Locked Moved ASP.NET
csharpjavajavascriptasp-netsysadmin
3 Posts 2 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.
  • K Offline
    K Offline
    kris_viswa
    wrote on last edited by
    #1

    Hi Gurus I am new to web programming and I started working with Asp.net 3.5 vwd express edition with ajax tool kit.For about a week now I screened most of articles on use of javascript in asp.net and following is suggested. 1. Use external script file and refer in masterpage and call from content pages by registerclientsciptblock On Master page it refered as follows" <script> 2.Place Java script functions in content place holders and refer them by adding attributes to controls. I tried using following function refering it in the clientvalidationfunction <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Enter Loan Account Name" ClientValidationFunction="chkloanac" OnServerValidate="Chk" ControlToValidate"TxtLoanSource" </asp:CustomValidator> <script type="text/jscript"> function chkloanac(source, arguments) { var Bal = document.getElementById("<%=TxtBalDebt.ClientID%>"); var acname = document.getElementById("<%=TxtLoanSource.ClientID%>"); if (Bal.value > 0 && (acname.value == 'NA' || acname.value == '')) arguments.IsValid = true; else arguments.IsValid = false; } 3.Build script strings and make call from code behind.example Dim sb As New System.Text.StringBuilder() sb.Append("") sb.Append("alert('Save Successful');") sb.Append("") ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Alert", sb.ToString(), False) All my pages are using ajax controls or extenders and i observe the folllowing. When I use method-1 and try register the code block, the image placed in a panel for controlling collapsable panel do not load. Method-2 is not working at all I created a function to refer in custom validation control which would not fire Only mehod-3 is working which again has limitation for using long functions I request an expert guidence on above subject with known issues and limitations if any.Preferably wih a working example on method-1 or method-2 Thanks in advance Kris

    N 1 Reply Last reply
    0
    • K kris_viswa

      Hi Gurus I am new to web programming and I started working with Asp.net 3.5 vwd express edition with ajax tool kit.For about a week now I screened most of articles on use of javascript in asp.net and following is suggested. 1. Use external script file and refer in masterpage and call from content pages by registerclientsciptblock On Master page it refered as follows" <script> 2.Place Java script functions in content place holders and refer them by adding attributes to controls. I tried using following function refering it in the clientvalidationfunction <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Enter Loan Account Name" ClientValidationFunction="chkloanac" OnServerValidate="Chk" ControlToValidate"TxtLoanSource" </asp:CustomValidator> <script type="text/jscript"> function chkloanac(source, arguments) { var Bal = document.getElementById("<%=TxtBalDebt.ClientID%>"); var acname = document.getElementById("<%=TxtLoanSource.ClientID%>"); if (Bal.value > 0 && (acname.value == 'NA' || acname.value == '')) arguments.IsValid = true; else arguments.IsValid = false; } 3.Build script strings and make call from code behind.example Dim sb As New System.Text.StringBuilder() sb.Append("") sb.Append("alert('Save Successful');") sb.Append("") ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Alert", sb.ToString(), False) All my pages are using ajax controls or extenders and i observe the folllowing. When I use method-1 and try register the code block, the image placed in a panel for controlling collapsable panel do not load. Method-2 is not working at all I created a function to refer in custom validation control which would not fire Only mehod-3 is working which again has limitation for using long functions I request an expert guidence on above subject with known issues and limitations if any.Preferably wih a working example on method-1 or method-2 Thanks in advance Kris

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      In method 1 it is unnecessary to use RegisterClientScript in the content pages since the script is already included as part of the master page. Whatever source told you to do it that way was utterly daft. If the script has been proper;y included then your functions should be available for use.


      I know the language. I've read a book. - _Madmatt

      K 1 Reply Last reply
      0
      • N Not Active

        In method 1 it is unnecessary to use RegisterClientScript in the content pages since the script is already included as part of the master page. Whatever source told you to do it that way was utterly daft. If the script has been proper;y included then your functions should be available for use.


        I know the language. I've read a book. - _Madmatt

        K Offline
        K Offline
        kris_viswa
        wrote on last edited by
        #3

        Thanks Mark let me try calling function directly from script file referenced in masterpage. kris

        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