Solved

java script in asp

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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