?
Solved

java script in asp

Posted on 2009-04-15
5
Medium Priority
?
402 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

752 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