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"
Expand|Select|Wrap|Line Numbers
- <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 clientvalidationfunction
Expand|Select|Wrap|Line Numbers
- <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
Expand|Select|Wrap|Line Numbers
- 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)
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