Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I think I got it down, but still need help.

Status
Not open for further replies.

DarkWorlds

Technical User
Jul 20, 2005
64
0
0
US
Ok I was not able to get anything in the two other threads I started started. So finely I sat down to do something VERY simple. But it seems its broke.

What I want to do is disable the button whuile a query runs to get the download. Well it does that just fine. Excepts it never un-disables the button when done. Please help me out with this. Here is the code.

Bankend
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.IO;

namespace Tester
{
	/// <summary>
	/// Summary description for WebForm3.
	/// </summary>
	public class WebForm3 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnBack;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			btnBack.Attributes.Add("onclick", GetPostBackEventReference(btnBack) + ";this.value='Please wait...';this.disabled = true;");
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnBack.Click += new System.EventHandler(this.btnBack_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnBack_Click(object sender, System.EventArgs e)
		{
			DataSet ds = new DataSet(); 
			DataTable dt = new DataTable("JohnsTable"); 
			ds.Tables.Add(dt); 
			DataColumn dc1 = new DataColumn("Name"); 
			DataColumn dc2 = new DataColumn("Valve"); 
			DataColumn dc3 = new DataColumn("Time"); 
			dt.Columns.Add(dc1); 
			dt.Columns.Add(dc2); 
			dt.Columns.Add(dc3);
			DataRow dr = dt.NewRow(); 
			dr["Name"] = "Jim"; 
			dr["Valve"] = "34"; 
			dr["Time"] = "12:00"; 
			dt.Rows.Add(dr);
			ExcelConvert(ds, Response);


	
		}
		
		public static void ExcelConvert(DataSet ds, HttpResponse response) 
		{ 
			string startDate = System.DateTime.Today.ToShortDateString();
			string endDate = System.DateTime.Today.AddDays(7).ToShortDateString();

			response.Clear(); 
			response.Charset = ""; 
			response.ContentType = "application/vnd.ms-excel"; 
			StringWriter stringWrite = new StringWriter(); 
			HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); 
			DataGrid dg = new DataGrid(); 
			dg.DataSource = ds.Tables[0]; 
			dg.DataBind(); 
			dg.RenderControl(htmlWrite); 
			Thread.Sleep(3000);
			response.Write(stringWrite.ToString()); 
			response.End(); 
		} 
	}
}

HTML
Code:
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="Tester.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>WebForm3</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="[URL unfurl="true"]http://schemas.microsoft.com/intellisense/ie5">[/URL]
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<form id="Form1" method="post" runat="server">
			<asp:Button id="btnBack" style="Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 56px" runat="server"
				Text="Button"></asp:Button>
		</form>
	</body>
</HTML>
 
Again because you never set it to be enabled again. Why not do this:
Code:
        private void btnBack_Click(object sender, System.EventArgs e)
        {
[b]btnBack.enabled = false;[/b]
            DataSet ds = new DataSet(); 
            DataTable dt = new DataTable("JohnsTable"); 
            ds.Tables.Add(dt); 
            DataColumn dc1 = new DataColumn("Name"); 
            DataColumn dc2 = new DataColumn("Valve"); 
            DataColumn dc3 = new DataColumn("Time"); 
            dt.Columns.Add(dc1); 
            dt.Columns.Add(dc2); 
            dt.Columns.Add(dc3);
            DataRow dr = dt.NewRow(); 
            dr["Name"] = "Jim"; 
            dr["Valve"] = "34"; 
            dr["Time"] = "12:00"; 
            dt.Rows.Add(dr);
            ExcelConvert(ds, Response);
[b]btnBack.enabled = true;[/b]
 
Well for giggles I tried that out, it doesnt work. Makes since that it should, but it doesnt.

This is what I have ran into with every "Please Wait" thing thus far. I am almost starting to think it cant be done.

If anyone has figured this out, let me know.
 
remove the javascript from the button that disables it on the click...
 
If I do that, im at problem one all over again.

Non of the enable funtions work in the button click event. With or without the java event. Try it out, and you will see.
 
But it seems its broke.
Nothing is broken, you just haven't understood the distinction between the client side events, the server side events and the order in which events fire. I suggest you read up on them here.

If you want a simple example, this is as simple as it can be:
Code:
    [Blue]Protected[/Blue] [Blue]Sub[/Blue] Button1_Click([Blue]ByVal[/Blue] sender [Blue]As[/Blue] Object, [Blue]ByVal[/Blue] e [Blue]As[/Blue] System.EventArgs) [Blue]Handles[/Blue] Button1.Click
        System.Threading.Thread.Sleep(5000)
        ClientScript.RegisterClientScriptBlock([Blue]Me[/Blue].GetType, [Red]"reset"[/Red], [Red]"document.getElementById('"[/Red] & Button1.ClientID & [Red]"').disabled=false;"[/Red], [Blue]True[/Blue])
    [Blue]End[/Blue] [Blue]Sub[/Blue]

    [Blue]Protected[/Blue] [Blue]Sub[/Blue] Page_Load([Blue]ByVal[/Blue] sender [Blue]As[/Blue] Object, [Blue]ByVal[/Blue] e [Blue]As[/Blue] System.EventArgs) [Blue]Handles[/Blue] [Blue]Me[/Blue].Load
        Button1.Attributes.Add([Red]"onclick"[/Red], ClientScript.GetPostBackEventReference(Button1, [Red]""[/Red]) & [Red]";this.value='Please wait...';this.disabled = true;"[/Red])
    [Blue]End[/Blue] [Blue]Sub[/Blue]


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
jbenson001's enable example wouldn't work. everything is happening on the server so your disabling and enabling the button in the same instance. this should work instead
Code:
private void Page_Load(object sender, System.EventArgs e)
{
   btnBack.Attributes.Add("onclick", ";this.value='Please wait...';this.disabled = true;");
}
private void btnBack_Click(object sender, System.EventArgs e)
{
     ...
     ExcelConvert(ds, Response);
     Page.ClientScript.RegisterStartUpScript(this.GetType(), "enablescript", "document.getElementById(" +  btnBack.ClientID + ").disabled = false;", true);
}
for more informatin check out the ClientScriptManager object. if you are using MS AJAX you need to reference the static [tt]ScriptManager.RegisterStartUpScript[/tt].

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
'System.Web.UI.Page' does not contain a definition for 'ClientScript'


Hmm, I am on VS2003 if it helps you out any on this one. I hope im not missing something thats stairing strait at me.
 
If you a problem with a class/object/method/property, type it into google and look at the help file. In this case, you would have seen this which contains the line:
Microsoft said:
The ClientScriptManager class is new in ASP.NET 2.0 and replaces Page class methods for managing scripts that are now deprecated.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
As I found out, but I didnt want to call the person out on it. Im just looking for a way to fix this.

Because if I find a way on this, maybe ill fix my other issues.

I look forward to the replies. Wish I has asp.net 2.0 and the other goodies that comes with it. My problems would have been solved days ago.
 
don't worry about "calling someone out", we are all here to help one another. if you don't "call mo on it" i won't realize the mistake I made.

in this case your using .net 1.1 and I gave you an example of 2.0 code.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top