Solved

java script in asp

Posted on 2009-04-15
5
400 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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