Solved

java script in asp

Posted on 2009-04-15
5
395 Views
Last Modified: 2012-05-06
i use radwindow in asp.net
when user click on button windows will close
but it not work when user click button and once it not close
when user click twice it close

protected void Button1_Click(object sender, EventArgs e)

    {

        if (Txtusername.Text == "ajay")

        {

            Button1.Attributes.Add("onclick", "Cancel_Clicked()");
 

        

        }
 
 

in aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ADLOGIN.aspx.cs" Inherits="administrator_ADLOGIN" %>
 

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    	<script type="text/javascript">

			//This code is used to provide a reference to the radwindow "wrapper"

    	    function GetRadWindow() {

    	        var oWindow = null;

    	        if (window.radWindow) oWindow = window.radWindow;

    	        else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;

    	        return oWindow;

    	    }		

			

						

			

			function Cancel_Clicked()

			{

				var oWindow = GetRadWindow();			

				oWindow.close();

			}				

		</script>	

    

    <div>

    

    </div>

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

        <telerik:RadTextBox ID="Txtusername" Runat="server">

        </telerik:RadTextBox>

        <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">

        </telerik:RadScriptManager>

    </form>

</body>

</html>

Open in new window

0
Comment
Question by:chandresh43
  • 3
  • 2
5 Comments
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 24146400
Hi chandresh43,
>>..when user click twice it close
Try this:

   Button1.Attributes.Add("onclick", "Cancel_Clicked();return false;");
 
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 24146439
Hi chandresh43,
One more thing, don't invoke button's onClick server event, but just call it via client script.
eg:

aspx
======
<asp:Button ID="Button1" runat="server" Text="Button" />

function ButtonJS_Click(){
  if (document.getElementById('<%=Txtusername.ClientID%>').value== 'ajay'){
       Cancel_Clicked();
  }
}

c#
====
Page Load event

If(!IsPostBack){
   Button1.Attributes.Add("onclick", "ButtonJS_Click();return false;");
}
       

0
 
LVL 5

Author Comment

by:chandresh43
ID: 24146532
ok when i
add on page load
If(!IsPostBack){
   Button1.Attributes.Add("onclick", "ButtonJS_Click();return false;");
}

it not create my session
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24146544

 its button 1 click event
 protected void Button1_Click(object sender, EventArgs e)
    {
        if (Txtusername.Text == "ajay")
        {
            Button1.Attributes.Add("onclick", "ButtonJS_Click();return false;");
            Session["aduserlogin"] = Txtusername.Text;
       
        }


    }
0
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 500 total points
ID: 24146707
Hi chandresh43,
Ok, if you need to store additional information before invoke client script, you can call client script function via code-behind.
eg:

protected void Button1_Click(object sender, EventArgs e)
    {
        if (Txtusername.Text == "ajay")
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "strJS", "Cancel_Clicked();", true);

            Session["aduserlogin"] = Txtusername.Text;
        }


    }
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now