Download presentation
Presentation is loading. Please wait.
Published byAmice Randall Modified over 9 years ago
1
ASP + JavaScript Client and Server scripts
2
Link 1 function MyClick(){ document.write("MyClick"); } function MyFunction1(){ alert("My Function 1"); }
3
Server side procedure for the previous screen void Page_Load(object sender, EventArgs e) { Response.Write("This procedure works on the server side"); }
4
Object Page Page.RegisterClientScriptBlock Page.RegisterStartupScript Page.RegisterOnSubmitStatement Page.isClientScriptBlockRegistered Page.RegisterHiddenField
5
Library of client scripts 1.Create html 2.Create JavaScripts 3. Add JavaScripts to HTML with the help of This.registerClientScriptBlock
6
Public void Page_Load(object sender, EventArgs e){ String scriptString=“ function DoClick(){”; scriptString+=“myForm.show.value=‘This is client script’}</”; scriptString+=“script>”; If (!this.isClientScriptBlockRegistered(“clientScript”)) This.RegisterClientScriptBlock(“clientScript”, scriptString); } ……….
7
Dynamic client script definition “Attributes” Void Page_Load(Object sender, EventArgs e){ TextBox1.Attributes[“onclick”]=“javascript:alert(‘you selected textfield’);”; } ….
8
Verifying data Void SubmitBtn(Object sender, EventArgs e) Message.Text=“server side function”; …. <asp:RequiredFieldValidator ControlToValidate=“Text” Display =“Dynamic” errormessage=“input the text” runat=server/>
9
Standard validators RequiredFieldValidator RangeValidator RegularExpressionValidator CustomValidator ValidationSummary
10
ValidationGroup Void Group1(Object s, EventArgs e) { If (Page.isValid){ lbl1.text=“group1”} …. Group1 Group2 item2 item3
11
Continue </asp:RequiredFieldValidator ValidationGroup=“VGroup2” id=“RequiredValidator1” ControlToValidate=“RudioButtonList1” ErrorMessage=“RadionButtonList” InitialValue=“” Width=“100%” Text=“*” runat=“server”/> <asp:requiredfieldvalidator validationgroup=“VGroup2” SetFocusOnError=“true” ErrorMessage=“TextBox2” ControlToValidate=“TextBox2” Text=“input text” runat=“server”/> <asp:validationsummary validationgroup=“VGroup2” id=“valSum” DisplayMode=“BulletList” runat=“server” ShowSummary=“True” ShowMessageBox=“true” HeaderText=“fill the fields:”/>
12
Code page and HTML page
13
Code.cs Using System; Using System.Web.UI; Using System.Web.UI.WebControls; System.Web.UI.HTMLControls; Public class MyClass:Page{ Public Label text; Public void SubmitBtnClick(Object sender, EventArgs e){ Text.Text=“This is code behind”; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.