Click here to Skip to main content
15,893,486 members
Articles / Web Development / ASP.NET

Use & Call RegisterStartUpScript, RegisterClientScript and Client-Side Script

Rate me:
Please Sign up or sign in to vote.
4.67/5 (35 votes)
5 Mar 2009CPOL1 min read 480.1K   3.6K   73  
This article helps a learner to know more about the different ways of calling client side JavaScript from server side code-behind.
<%@ Page language="c#" Codebehind="ClientServer.aspx.cs" AutoEventWireup="false" Inherits="RegisterClientServerProc.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>WebForm1</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<script>
		
		function ReqField1Validator()
		{ 
		 if (document.forms[0].txtField1.value == '') 
			{
				alert('TextBox cannot be empty') 
				return false
			} 
				return true 
		} 
				
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<asp:Label id="Label3" runat="server" Width="200px" Font-Bold="True" style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 56px">1) RegisterStartupScript:</asp:Label>
			<asp:Label id="Label2" runat="server" Width="240px" Height="27px" Font-Bold="True" Font-Size="Large"
				style="Z-INDEX: 103; LEFT: 144px; POSITION: absolute; TOP: 16px">Demonstration</asp:Label><A onclick="JavScriptFn()">
				<asp:Label id="Label1" runat="server" Width="281px" ForeColor="#8080FF" style="Z-INDEX: 104; LEFT: 216px; POSITION: absolute; TOP: 72px">Click to call Javascript function.</asp:Label></A>
			<asp:Label id="Label4" runat="server" Font-Bold="True" style="Z-INDEX: 105; LEFT: 24px; POSITION: absolute; TOP: 96px">2) RegisterClientScriptBlock :</asp:Label>
			<asp:Button id="btnClientBlock" runat="server" Text="Client ScriptBlock" style="Z-INDEX: 106; LEFT: 208px; POSITION: absolute; TOP: 128px"></asp:Button>
			<asp:Label id="lblSequencial" runat="server" Width="272px" Font-Bold="True" ForeColor="#FF8080"
				style="Z-INDEX: 107; LEFT: 400px; POSITION: absolute; TOP: 128px"></asp:Label>
			<asp:Label id="Label5" runat="server" Width="152px" Font-Bold="True" style="Z-INDEX: 108; LEFT: 32px; POSITION: absolute; TOP: 160px">3) Register Event :</asp:Label>
			<asp:TextBox id="txtField" runat="server" Width="152px" style="Z-INDEX: 109; LEFT: 208px; POSITION: absolute; TOP: 208px"></asp:TextBox>
			<asp:Button id="btnSubmit" runat="server" Text="Submit" style="Z-INDEX: 110; LEFT: 416px; POSITION: absolute; TOP: 208px"></asp:Button>
			<asp:Label id="Label6" runat="server" Width="208px" Font-Bold="True" style="Z-INDEX: 111; LEFT: 208px; POSITION: absolute; TOP: 168px">Client Script in code behind</asp:Label>
			<asp:TextBox id="txtField1" runat="server" Width="152px" style="Z-INDEX: 112; LEFT: 208px; POSITION: absolute; TOP: 288px"></asp:TextBox>
			<asp:Label id="Label7" runat="server" Width="216px" Font-Bold="True" style="Z-INDEX: 113; LEFT: 208px; POSITION: absolute; TOP: 248px"
				Height="16px">Client Script in a HTML page</asp:Label>
			<asp:Button id="btnOK" runat="server" Text="OK" style="Z-INDEX: 114; LEFT: 432px; POSITION: absolute; TOP: 248px"></asp:Button>
		</form>
	</body>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Australia Australia
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

Comments and Discussions