Monday, March 19, 2007

Calling Server Function From JavaScript

HTML Part

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
                                AutoEventWireup="false" Inherits="CallServerFun.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 Ul()
{
var b=document.getElementById("Bt");
b.click();
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" onunload="Ul()">
<form id="Form1" method="post" runat="server">
<button id="Bt" name="Bt" style="DISPLAY:none"
            runat="server" type="button"></button>
</form>
</body>
</HTML>


Code Behind

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CallServerFun
{
///
/// Summary description for WebForm1.
///

public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlButton Bt;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.Bt.ServerClick += new System.EventHandler
                                 (this.Bt_ServerClick);
this.Load += new System.EventHandler
                              (this.Page_Load);
}
#endregion

private void Bt_ServerClick(object sender,
                             System.EventArgs e)
{
Response.Write("http://www.google.com");
}
}
}



No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.