Pages

Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

Saturday, December 22, 2012

How to Close Window Using Javascript


Window.Close() method is used for close window using JavaScript in HTML

Example :

<input type="button" value="Close" class="button" onclick="window.opener=null; window.close(); return false;">

HTML Example For Open Window and Close Window on Button Click Event:
Example :

<html>
<head>
    <script>

        function openWin() {
            myWindow = window.open("", "", "width=200,height=100");
            myWindow.document.write("<p>This is 'myWindow'</p>");
        }

        function closeWin() {
            myWindow.close();
        }
    </script>
</head>
<body>
    <input type="button" value="Open 'myWindow'" onclick="openWin()">
    <input type="button" value="Close 'myWindow'" onclick="closeWin()">
</body>
</html>


Window.Close() method is used for close window using JavaScript in ASP.NET
 
Example :
<asp:Button ID="Button2" runat="server" Text="Close" OnClientClick="javascript: window.close();"/>

  

#ASP.NET, #JAVASCRIPT,#CLOSE WINDOW
 

Friday, March 23, 2012

Bind Dropdown Using Javascript and Webservice

1) Add Webservice wsCountry.asmx

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Services;
using System.Web.Services;
using Test;
///


/// Summary description for wsCountry
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class wsCountry : System.Web.Services.WebService
{

    public wsCountry()
    {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }
  
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
    public List FindAllCountries()
    {
        List locations = new List();
        string connectionString = ConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString;
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.Connection = connection;
                command.CommandText = "SelectAllCountries";
                command.CommandType = CommandType.StoredProcedure;
                connection.Open();
                using (SqlDataReader dataReader = command.ExecuteReader())
                {
                    Location location;
                    if (dataReader != null)
                        while (dataReader.Read())
                        {
                            location = new Location();
                            location.CountryID = (int)dataReader["CountryID"];
                            location.CountryName = Convert.ToString(dataReader["CountryName"]);
                            locations.Add(location);
                        }
                }
            }
        }
        return locations;
    }
}
namespace Test
{
    [Serializable]
    public class Location
    {
        public int CountryID
        { get; set; }

        public string CountryName
        { get; set; }

    }
}



2) Add ASPX Page and Call web service method.
Add script manager
Add Service Reference in the script Manager
Call Web service on the page load and get result and add that result to Dropdown.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BindDropDown.aspx.cs" EnableEventValidation="false"  Inherits="BindDropDown" %>




    Bind Dropdown


   


   

       
           
               
           

       

   

   

   

   
   
   



Wednesday, September 2, 2009

Set Session variable in javascript function


How can I set session variables with JavaScript ?

Sample Code In Java script:
<script language="javascript" type="text/javascript">
          function SendRequest() {
          var MySessionvalue = '<%= Session["EMP_C"] %>';
          var MyColocn = '<%= Session["COLOCN_C"] %>';
          alert(MySessionvalue);           
          }
< /script>

#How can I set session variables with JavaScript
#Assigning Session variable from Javascript
#How do i set a session variable using javascript?

Tuesday, August 11, 2009

OPENING NEW WINDOWS

var newwindow;
function openwindow(url)
{
newwindow=window.open(url,'name','height=800,width=600');
if (window.focus) {newwindow.focus()}
}

Monday, May 25, 2009

How To Generate IFrame At Runtime Using Javascript


<script type="text/javascript">
var el = document.createElement("iframe");
el.setAttribute('id', 'ifrm');
el.setAttribute('width', '100%');
document.body.appendChild(el);
el.setAttribute('src', 'http://www.yahoo.com');
script>

Thursday, May 14, 2009

How to Print Div Tag Using Javascript?



HTML FILE :

<script language="javascript">

function CallPrint( strid )

{

var prtContent = document.getElementById( strid );

var WinPrint = window.open('', '', 'left=0,top=0,width=900,height=600,toolbar=1,scrollbars=1,status=0');

WinPrint.document.write( prtContent.innerHTML );

WinPrint.document.close();

WinPrint.focus();

WinPrint.print();

WinPrint.close();

prtContent.innerHTML=strOldOne;

}

script>

<div id="print_Grid">

This is Print

This is Print

This is Print

This is Print

This is Print

div>



Code FILE :


protected void Page_Load(object sender, EventArgs e)

{

btnPrint.Attributes.Add("onclick", "javascript:CallPrint('print_Grid')");

}


How To Use This Code?

1. Copy JavaScript into your HTML Page

2. Make a Div Tag Which data you want to print into that div tag

3. Add Print Button and call JavaScript Function




Wednesday, April 1, 2009

confirmation message on delete in a gridview

protected void gridOverview_OnRowDataBound(object sender, GridViewRowEventArgs e)
//Add delete msgbox to each row containing field
//information to identify the row
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// reference the Delete ImageButton
ImageButton ib = (ImageButton)e.Row.FindControl(“ibDelete”);
ib.Attributes.Add(“onclick”,“javascript:return ” +
confirm(’Are you sure about deleting ” +
DataBinder.Eval(e.Row.DataItem, ColomnName) + “?’);”);
}
}

OR


Add New Client Click property of button
return confirm(’Are you sure about deleting ”);

OR
Use Ajax Extender for confirmation box
<asp:TemplateField HeaderText=”Delete” >
<ItemStyle CssClass=”grid-column-buttons” />
<ItemTemplate>
<asp:ImageButton ID=”ibDelete” runat=”server”
CausesValidation=”False” CommandName=”Delete”
ImageUrl=”~/Images/icon-delete.gif” />
<ajaxToolkit:ConfirmButtonExtender ID=”ConfirmBtExt1″
runat=”server” TargetControlID=”ibDelete”
ConfirmText=’Are you sure about deleting this record?’ />
ItemTemplate>
asp:TemplateField>


ShareThis

Welcome

Welcome to Rajesh Prajapati, asp.net blog.
Here you can find some useful code and information about asp.net., c#, VB.net, SQL Server, Web Service, Web Designing etc