m using Asp.Net 2005 and i wud like to close my application when i click button .
i gave Response.close()......and end() but its not coming ..
when i give Response.end() then i m getting this error

[XML Parsing Error: no element found
Location: http://localhost:2366/hlpdsk/just1.aspx
Line Number 1, Column 1:]

finally i gave

Button1.Attributes.Add("OnClick", "self.close()");
and onclick="window.close()"

that too not working so pls help me

Thank you,

Recommended Answers

All 4 Replies

Hi

please write the following code alone Button1.Attributes.Add("onclick", "window.close();");

Remove rest of the things

Regards
razool

Hi

please write the following code alone Button1.Attributes.Add("onclick", "window.close();");

Remove rest of the things

Regards
razool

hi i did as you told ..after tha too tat page is not closed
pls give some other suggestion
thank you,

Please write the code

Button1.Attributes.Add("onclick", "window.close();");


page Load Event. Remove the rest of the things. if you still getting error send you aspx,aspx.cs page i will guide you

Regards
razool

this code behind
==========

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Xml;

public partial class Login : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader dr;

    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection("server=SOFTWARE4;uid=sa;pwd=;database=helpdesk1");
        con.Open();
        Button1.Attributes.Add("onclick", "window.close();");
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
       //Response.Write("<script language='Javascript'>{self.opener=top;self.close()}<"+"/script>");
        
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {   //SqlCommand cmd = new SqlCommand("select user_name,user_id,password from helpdesk_admin where user_id=@id and password=@pass", con1);
        //string name = uname.Text.Trim();
        //cmd.Parameters.Add("@id", uname.Text.ToString().Trim());
        //cmd.Parameters.Add("@pass", pass.Text.ToString().Trim());
        //SqlDataReader dr;
        //dr = cmd.ExecuteReader();

        string k = "select uname,uid,pass from login where uid='" + txt_uname.Text + "'and pass='" + txt_pass.Text+ "'";
       
        cmd = new SqlCommand(k, con);
        string name = txt_uname.Text;
        dr = cmd.ExecuteReader();
        if (dr.Read() == true)
        {
            if (name.StartsWith("It_"))
            {
                // Session["It_user"] = dr["uname"].ToString();
                Session["users"] = dr["uname"].ToString();
                Session["username"] = txt_uname.Text.ToString();
                //Response.Redirect("Ituser.aspx");
                Response.Redirect("it.aspx");
            }
            else if (name.StartsWith("MIt_"))
            {
                    //Session["manager"] = dr["uname"].ToString();
                Session["users"] = dr["uname"].ToString();
                Session["username"] = txt_uname.Text.ToString();
               // Response.Redirect("Datagrid.aspx");
                Response.Redirect("just1.aspx");                   
             }
            else
            {
                Label3.Visible = true;
                Label3.Text = "";
                Label3.Text = "<B><font size='3' color='darkorchid'>CHECK Whether Your USERID Starts With CAPS</font></B>";
            }
        }
        else
        {
            Label3.Text = "";
            Label3.Visible = true;
            //Label3.Text = "Check your user id and password correctly";
            Label3.Text = "<B><font size='3' color='DarkOrchid'>CHECK Whether Your USERID Starts With CAPS And CHECK Password</font></B>";
            txt_uname.Text = " ";
            txt_pass.Text = " ";
        }
        dr.Close();
    }      
    //protected void Button1_Click(object sender, EventArgs e)
    //{
    //    //Button1.Attributes.Add("OnClick","window.Close()");
    //    //Button1.Attributes.Add("OnClick", "self.Close()");
    //    //Response.Close();
    //    Response.Write("<script>alert('hai')</script>");
    //    //Response.Write("<script>window.close();</script>");
    //    Button1.Attributes.Add("onclick", "return closeme();");
    //}
    
}

this is html coding
============

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

<!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>Untitled Page</title>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Image ID="Image1" runat="server" Height="96px" ImageUrl="~/a.jpg" Width="818px" /><br />
        <br />
        <br />
        
        
        <asp:Button ID="Button1" runat="server" Text="Button" />
       
        <asp:Image ID="Image2" runat="server" Height="73px" ImageUrl="~/a1.jpg" Width="178px" /><br />
        <br />
        <br />        
        <asp:Label ID="Label1" runat="server" Font-Bold="True" Text="User Name" Width="92px"></asp:Label>
        &nbsp;
        <asp:TextBox ID="txt_uname" runat="server"></asp:TextBox>
        <br />
        <br />
     
        <asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Password" Width="90px"></asp:Label>
        &nbsp; &nbsp; &nbsp;
        <asp:TextBox ID="txt_pass" runat="server"></asp:TextBox>
        <br />
        <br />
        
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Width="39px">Login</asp:LinkButton>
        &nbsp; &nbsp; &nbsp;
        <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click" Width="49px">Cancel</asp:LinkButton>
        <br />
        <br />
        <br />
        
        <asp:Label ID="Label3" runat="server" Text="Label"  Visible="False" Width="735px"></asp:Label>
        &nbsp;
        <br />
        <br />
        <br />
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>

i just used button1 for example so just help me to come the answer.

even i tried in html button(<input type=button>) tat too its not coming

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.