Use of Javascript in Asp.net Ajax enabled content pages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krisviswa
    New Member
    • Mar 2010
    • 6

    Use of Javascript in Asp.net Ajax enabled content pages

    Hi

    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 registerclients ciptblock
    On Master page it refered as follows"
    Code:
    <script type="text/javascript" src="~/Scripts/TestScript.js">
    
    </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 clientvalidatio nfunction
    Code:
    <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;
     }
    
    </script>


    3.Build script strings and make call from code behind.example
    Code:
    Dim sb As New System.Text.StringBuilder() 
    
    sb.Append("<script language='javascript'>")
    sb.Append("alert('Save Successful');")
    sb.Append("</script>")
                                    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

    3.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
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Are you using UpdatePanels?
    If you are then you have to use the third method to register your script or else it will stop working after a control within the UpdatePanel posts back to the server.

    Could you explain what you're trying to accomplish so that I can help you further?

    -Frinny

    Comment

    Working...