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!

Help getting demo to work.

Status
Not open for further replies.

DarkWorlds

Technical User
Jul 20, 2005
64
0
0
US
Ok, well i know this may look like I posted up something similar a dar or two ago.


Well since no one can help me out on that, then I need to move on. This is yet another please wait. But I am having a problem getting the demo to work at all. I am hoping that someone can fill in the blanks for me.

Code:
<%@Page Language="VB" Debug="True" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Threading" %>

<script runat="server">

Sub Page_Load()

  If Page.IsPostback Then

    ' user submitted page with customer ID
    ' create URL with query string for customer ID
    ' next page will not be a postback, so viewstate will be lost
    Dim sRefreshURL As String = Request.Url.ToString() _
      & "?custID=" & txtCustomer.Text

    ' use META REFRESH to start loading next page
    mtaRefresh.Attributes.Add("http-equiv", "refresh")
    mtaRefresh.Attributes.Add("content", "0;url=" & sRefreshURL)

    ' hide <form> section and show "wait" section
    frmMain.Visible = False
    divWait.Visible = True

  Else

    ' get customer ID from query string
    Dim sCustID As String = Request.QueryString("custID")

    If sCustID > "" Then

      ' page is loading from META REFRESH element and
      ' so currently shows the "please wait" message
      ' a customer ID was provided so display results
      divResult.Visible = True

      ' set URL for "Next Customer" hyperlink
      lnkNext.NavigateUrl = Request.FilePath

      ' get data and bind to DataGrid in the page
      FillDataGrid(sCustID)

    Else

      ' either this is the first time the page has been
      ' loaded, or no customer ID was provided
      ' display controls to select customer
      frmMain.Visible = True

    End If
  End If

End Sub

<%-------------------------------------------------------------%>

Sub FillDataGrid(sCustID As String)

  Dim sSelect As String _
    = "SELECT CustomerID, CompanyName, City, Country, Phone " _
    & "FROM Customers WHERE CustomerID LIKE @CustomerID"
  Dim sConnect As String _
    = ConfigurationSettings.AppSettings("NorthwindSqlClientConnectString")
  Dim oConnect As New SqlConnection(sConnect)

  Try

    ' get DataReader for rows from Northwind Customers table
    Dim oCommand As New SqlCommand(sSelect, oConnect)
    oCommand.Parameters.Add("@CustomerID", sCustID & "%")
    oConnect.Open()
    dgrResult.DataSource = oCommand.ExecuteReader()
    dgrResult.DataBind()
    oConnect.Close()
    lblResult.Text = "Results of your query for Customer ID '" _
                   & sCustID & "'"

    ' force current thread to sleep for 3 seconds
    ' to simulate complex code execution
    Thread.Sleep(3000)

  Catch oErr As Exception

    oConnect.Close()
    lblResult.Text = oErr.Message

  End Try

End Sub

</script>

<!------------------------------------------------------------->
<!------------------------------------------------------------->

<html>
<head>

<!----- dynamically filled META REFRESH element ----->
<meta id="mtaRefresh" runat="server" />

<!-- #include file="../global/style.inc" -->
<title>Displaying a "Please Wait" Message</title>
</head>
<body>
<span class="heading">Displaying a "Please Wait" Message</span><hr />

<!----- form for selecting customer ----->
<form id="frmMain" Visible="False" runat="server">
  Enter Customer ID:
  <asp:Textbox id="txtCustomer" runat="server" />
  <asp:Button id="btnSubmit" Text="Go" runat="server" />
</form>

<!----- "please wait" display ----->
<div id="divWait" Visible="False" runat="server">
  <center>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <b>Searching, please wait...</b><p />
  <p>&nbsp;</p>
  <span id="spnError"></span>
  <p>&nbsp;</p>
  </center>
</div>

<!----- section for displaying results ----->
<div id="divResult" Visible="False" runat="server">
  <b><asp:Label id="lblResult" runat="server" /></b><p />
  <asp:DataGrid id="dgrResult" runat="server" /><p />
  <asp:Hyperlink id="lnkNext" Text="New Customer" runat="server" />
</div>

<p />
<span class="cite">
Remember to edit the connection strings in web.config file
for the Northwind sample database.
</span>
<hr />
<!-- #include file="../global/viewsource.inc" -->
<!-- #include file="../global/footer.inc" -->

</body>
</html>

Now I am running VS 2003 with asp.net 1.1 if it helps. I tried just to get it to run via VB and it wouldnt even go. So when I converted it over to c# it was a no go.

So help on this, or my past thread would be very helpfull. I am just trying to help out the user.
 
The first thing I would do is to get rid of the inline coding you are using, that is classic ASP style. Use the code behind file. Also, include files will not work that way. You will have to include them differently
 
Well I thought I did it right (didnt include the include files). But when I ran it, it bombed something horrid. Heck ill take the same demo but with Thread.Sleep(3000) as the action insteal of the sql connect. Like I said, I tried to do that and got errors all over the place.

Can anyone get this to work at all, or is this a lost hope?
 
Ok, this is the best I could do

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.Data.SqlClient;
using System.Threading;

namespace TestRun
{
	/// <summary>
	/// Summary description for Test1.
	/// </summary>
	public class Test1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtCustomer;
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.Label lblResult;
		protected System.Web.UI.WebControls.DataGrid dgrResult;
		protected System.Web.UI.WebControls.HyperLink lnkNext;
		protected System.Web.UI.HtmlControls.HtmlGenericControl divWait;
		protected System.Web.UI.HtmlControls.HtmlGenericControl divResult;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Page.IsPostBack) 
			{ 
				string sRefreshURL = Request.Url.ToString() + "?custID=" + txtCustomer.Text; 
				mtaRefresh.Attributes.Add("http-equiv", "refresh"); 
				mtaRefresh.Attributes.Add("content", "0;url=" + sRefreshURL); 
				frmMain.Visible = false; 
				divWait.Visible = true; 
			} 
			else 
			{ 
				//string sCustID = Request.QueryString("custID"); 
				//if (sCustID > "") 
				//{ 
					divResult.Visible = true; 
					lnkNext.NavigateUrl = Request.FilePath; 
					FillDataGrid("thy"); 
				//} 
				//else 
				//{ 
					frmMain.Visible = true; 
				//} 
			}

		}

		void FillDataGrid(string sCustID) 
		{ 
			Thread.Sleep(3000); 
		}


		#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.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

	}
}
And now the ASP code
Code:
<%@ Page language="c#" Codebehind="Test.aspx.cs" AutoEventWireup="false" Inherits="TestRun.Test1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>


<title>Displaying a "Please Wait" Message</title>

<!----- dynamically filled META REFRESH element ----->
<meta id=mtaRefresh runat="server" />
  </HEAD>
<body><span class=heading>Displaying a 
"Please Wait" Message</SPAN>
<hr>

<!----- form for selecting customer ----->
<form id=frmMain runat="server" Visible="False">Enter 
Customer ID: <asp:textbox id=txtCustomer runat="server"></asp:Textbox><asp:button id=btnSubmit runat="server" Text="Go"></asp:Button></FORM>

<!----- "please wait" display ----->
<div id=divWait runat="server" Visible="False">
<center>
<p>&nbsp;</P>
  <p>&nbsp;</p><b>Searching, please 
wait...</B>
<p>
<p>&nbsp;</P><span id=spnError></SPAN>
<p>&nbsp;</P></CENTER></DIV>

<!----- section for displaying results ----->
<div id=divResult runat="server" Visible="False">
<b><asp:label id=lblResult runat="server"></asp:Label></B>
<p><asp:datagrid id=dgrResult runat="server"></asp:DataGrid>
<p>
  <asp:Hyperlink id="lnkNext" Text="New Customer" runat="server" /></P>
  </DIV>

<p >
<span class="cite">
Remember to edit the connection strings in web.config file
for the Northwind sample database.
</span>
<hr >


</body>
</HTML>

This doesnt work, whats wrong? *sigh*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top