Use of Javascript in ajax enabled Asp.net content pages
-
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
-
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
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
-
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
Thanks Mark let me try calling function directly from script file referenced in masterpage. kris