Print Page | Close Window

Strange problem :( 2 clicks b4 it works!

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=9806
Printed Date: 28 March 2026 at 6:27pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Strange problem :( 2 clicks b4 it works!
Posted By: MrCarl
Subject: Strange problem :( 2 clicks b4 it works!
Date Posted: 13 February 2004 at 12:34pm

Hi,

I have setup a form which has a search textbox which you can either leave blank to search for all, or enter a number for it to query the database with.

It all seems to work fine, except if I put a number into the textbox I and click the submit button it doesnt query the database correctly and stays the same, but if I click it a second time it works!! really strange... Please helpn and let me know where im going wrong!!

Here is the code...

Thanks

- Carl

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

 Sub Page_Load(sender as Object, e as EventArgs)

 End Sub
 
 Sub subPurchaseOrderSearch(sender As Object, e As ImageClickEventArgs)

  Dim conSql as New SqlConnection(ConfigurationSettings.AppSettings("strCon"))
  Dim strSql as String = "SELECT tblPurchaseOrders.intPoNumber, tblPurchaseOrders.datRaised, tblPurchaseOrders.decAmount, tblPurchaseOrders.strStatus " _
        & "FROM tblPurchaseOrders "
  
  Dim sbSqlWhere as StringBuilder = New StringBuilder()

  If Not frmOrderNo.Text = "" Then sbSqlWhere.Append("WHERE tblPurchaseOrders.intPoNumber = " & frmOrderNo.Text)
    
  Dim comSql as New SqlCommand(strSql & sbSqlWhere.ToString(), conSql)

  conSql.Open()
  dgPurchaseOrderList.DataSource = comSql.ExecuteReader(CommandBehavior.CloseConnection)
  dgPurchaseOrderList.DataBind()
  conSql.Close()
 
 End Sub
 
 Sub subPurchaseOrderView(sender as Object, e As DataGridCommandEventArgs)
 
  Dim idJobVacancy as Integer = Convert.ToInt32(e.Item.Cells(0).text)
  Response.Redirect("PurchaseOrderView.aspx?id=" & idJobVacancy)
  
 End Sub

</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd - http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<title>Westmead - Driven by the Future</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="/sty/MainStyle.css" type="text/css" rel="stylesheet">
<script language="javascript" src="/inc/incFormFunctions.js"></script>
</head>
<body>
<form enctype="multipart/form-data" runat="server">
  <asp:TextBox id="frmOrderNo" tabIndex="2" runat="server" CssClass="form" AutoPostBack="true" MaxLength="10" TextMode="SingleLine" />
  <asp:ImageButton AlternateText="Click here to search for vacancy" id="ImageButton" ImageUrl="gfx/button_search.gif" runat="server" tabIndex="6" OnClick="subPurchaseOrderSearch" />
  <br>
  <asp:datagrid id="dgPurchaseOrderList" runat="server" CssClass="tableStyle1" AutoGenerateColumns="false" BorderColor="#000000" BorderStyle="Solid" CellPadding="5" CellSpacing="0" Width="100%" OnItemCommand="subPurchaseOrderView">
    <HeaderStyle cssclass="bold" />
    <AlternatingItemStyle cssclass="tableRow2" />
    <ItemStyle cssclass="tableRow1" />
    <Columns>
    <asp:BoundColumn DataField="intPoNumber" HeaderText="P/O Number" />
    <asp:BoundColumn DataField="datRaised" HeaderText="Date" />
    <asp:BoundColumn DataField="decAmount" HeaderText="Value" />
    <asp:BoundColumn DataField="strStatus" HeaderText="Status" />
    <asp:ButtonColumn Text="View" HeaderText="View" />
    </Columns>
  </asp:datagrid>
</form>
</body>
</html>




Replies:
Posted By: Diep-Vriezer
Date Posted: 13 February 2004 at 4:12pm
Looks like you're temp. inet files are filled or something. Try displaying the results on another page, and it won't happen again. How to solve it.. Hmm. Try deleting your temp inet files, then rebuild (or rerun) the application and see.

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 13 February 2004 at 4:14pm
Btw, the conSQL.Close() isn't needed, since you're closing the connection using Commandbehavior.CloseConnection right?

-------------
Gone..


Posted By: Mart
Date Posted: 13 February 2004 at 4:26pm
I had a similar problem once, can't think off hand how I solved it... I will get back to you if I remember.


Posted By: michael
Date Posted: 13 February 2004 at 5:49pm

Originally posted by Diep-Vriezer Diep-Vriezer wrote:

Btw, the conSQL.Close() isn't needed, since you're closing the connection using Commandbehavior.CloseConnection right?

Actually the opposite, with commandbehaviour.closeconnection you explicity tell the page that you will close the connection.



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Diep-Vriezer
Date Posted: 13 February 2004 at 6:41pm


-------------
Gone..


Posted By: Bunce
Date Posted: 15 February 2004 at 9:51pm

That option will close the connection when you close the reader.



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: michael
Date Posted: 15 February 2004 at 10:15pm
Right, I should have explained myself better
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataodbcodbccommandclassexecutereadertopic2.asp - http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/cpref/html/frlrfsystemdataodbcodbccommandclassexecutere adertopic2.asp

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: MrCarl
Date Posted: 16 February 2004 at 4:57am

OK... Fresh day at work, and I have seemed to fixed it :) Just removed the AutoPostBack="true" from the asp:TextBox and its all fine now...

If anyone knows why this might have been then please let me know!!

Oh and with this closing of connection, do I have to change conSql.Close() to comSqlClose() (to close the command instead of the connection??) or do I just take conSql.Close() out completely??

- Carl S




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net