Monday 23 January 2012

First Application Using JavaScript, How to access a URL of parent page in ASP. net, Confirm Box in JavaScript in use asp.net, Prompt Box in JavaScript in use asp.net

First Application Using JavaScript
Step 1. Written below code in your application.


<script language="javascript">
function displayDate()
{
alert(Date());
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Display</title>
</head>

<body>
    <form id="form1" runat="server">
    <div>
    <button type="button" onclick="displayDate()">DisplayDate</button>
    </div>
    </form>
</body>
</html>
 
 
How to access a URL of parent page in ASP. net 


Step 1. Open a new website,  add a button and textboxes control and named this page iframe.aspx. Design code is given below



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="iframe.aspx.cs" 
Inherits="iframe" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript" src="JScript.js">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body><form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server">
    </asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server" 
    style="top: 66px; left: 10px; position: absolute; height: 22px; width: 
        128px">
    </asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" 
    style="top: 120px; left: 12px; position: absolute; height: 26px; width: 
        56px" OnClientClick="uro()"/>
    </div>
    </form></body>
</html>
Step 2. Add a JavaScript file from Solution Explorer window
The code is written in JavaScript file is
function uro()
{
alert(parent.document.location.href);
}
function url()
{
alert(document.location.href);
}
Below code written in the design page to attached the JavaScript file to your project
<script language="javascript" src="JScript.js">
</script>
Step 3. Add another page from new item selection menu. The design code of this page is (url.aspx)

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="url.aspx.cs" 
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript" src="JScript.js">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>url</title>
</head>
<body>
    <form id="url" runat="server">
    <div>
   <asp:Button ID="Button1" runat="server" Text="Button" 
   onclientclick="url()"/>
   <iframe src="iframe.aspx" align="middle" height="350px" 
   name="Comments">
   </iframe>
   </div>
    </form>
</body>
</html>
Step 4. Now run the Application.



 
 
 
Confirm Box in JavaScript in use  asp.net 


Step 1. Written below code in your application.
<html>
<head>
<script type="text/javascript">
function show_box()
{
var r=confirm("Press a button");
if (r==true)
  {
  alert("You pressed OK!");
  }
else
  {
  alert("You pressed Cancel!");
  }
}
</script>
</head>
<body>
<input type="button" onclick="show_box()" value="Confirm box" />
</body>
</html>
Step 2. Run the Application. Click on Button.









Prompt Box in JavaScript  in use asp.net 




A prompt box is often used if you want the user to input a value before entering a page.
Step 1. Written below code in your application.
<html>
<head>
<script type="text/javascript">
function show_box()
{
var name=prompt("Please enter your name","Aditya Tiwari");
if (name!=null && name!="")
  {
  document.write("Hello " + name + "! How are you today?");
  }
}
</script>
</head>
<body>
<input type="button" onclick="show_box()" value="Show" />
</body>
</html>
Step 2. Run the Application. Click on Button.

You Entered the Website
















all source to use r4r.o.in site

No comments :