Solved

java script in asp

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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