asafblasberg
Programmer
Hello, I have a problem. I have a textbox with a Search button. You enter the description in the box, then hit the button and within the same page, the saerch results come up. However, if you hit ENTER instead of the acutal BUTTON, it does NOT work!
(You can try it yourself go to
What the heck is going on?
CODE IS HERE:
<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Protected strConn as String
Protected thesubcategory as string
Sub SrchResult()
strConn = ConfigurationSettings.AppSettings("testclub")
Dim CommandText as String = "SELECT * from products WHERE active = -1 AND " _
& "SKU LIKE '%" & frmsearch.text & "%' OR DESCRIPTION LIKE '%" & frmsearch.text & "%'"
Dim myConnection As New SqlConnection(strConn)
Dim objDR as SQLDataReader
Dim myCommand As New SqlCommand(CommandText, myConnection)
MyConnection.Open()
objDR=myCommand.ExecuteReader()
SearchResults.DataSource = objDR
SearchResults.DataBind()
End Sub
Sub ButtonSearch_Click(sender As Object, e As EventArgs)
SrchResult()
End Sub
Sub Page_Load(sender As Object, e As EventArgs)
End Sub
</script>
<html>
<head>
<body topmargin="0" leftmargin="0">
<form runat="Server">
<asp:textbox cssclass="gbbodynormal" id="frmsearch" runat="server" size="15"></asp:textbox>
<br><asp:button cssclass="gbbodynormal" runat="server" id="searchbutton" text="Search" onclick="buttonsearch_click"></asp:button></div>
<aspataList id="searchresults" horizontalAlign="Center" repeatcolumns="3" cssclass = "gbhead" halign="center" ItemStyle-VerticalAlign="Top" itemstyle-horizontalalign= "Center" ItemStyle-Width = "300" width="100%" repeatlayout="table" runat="server">
<ItemStyle CssClass="dash"></ItemStyle>
<itemtemplate>
<p align="center">
<a href="viewproduct.aspx?pid=<%# DataBinder.Eval(Container.DataItem, ("idProduct"))%>&mcat=<%# DataBinder.Eval(Container.DataItem, ("mastercategory"))%>&id=<%# DataBinder.Eval(Container.DataItem, ("idcategory"))%>">
<asp:Image id="Image1" runat="server" src='<%# DataBinder.Eval(Container.DataItem, ("smallimageurl"))%>'>
</asp:Image></a><br>
<%# DataBinder.Eval(Container.DataItem, ("sku"))%><br>
<b><%# DataBinder.Eval(Container.DataItem, ("description"))%></b><br>
List Price: <%# DataBinder.Eval(Container.DataItem, ("listprice"), "{0:c}")%><br>
<b><font color="#CC0000">Sale Price: <%# DataBinder.Eval(Container.DataItem, ("price"), "{0:c}")%><br></font>
<b><font size="3"></font>
</itemtemplate>
</aspataList>
</div>
</form>
</span>
</body>
</html>
(You can try it yourself go to
What the heck is going on?
CODE IS HERE:
<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Protected strConn as String
Protected thesubcategory as string
Sub SrchResult()
strConn = ConfigurationSettings.AppSettings("testclub")
Dim CommandText as String = "SELECT * from products WHERE active = -1 AND " _
& "SKU LIKE '%" & frmsearch.text & "%' OR DESCRIPTION LIKE '%" & frmsearch.text & "%'"
Dim myConnection As New SqlConnection(strConn)
Dim objDR as SQLDataReader
Dim myCommand As New SqlCommand(CommandText, myConnection)
MyConnection.Open()
objDR=myCommand.ExecuteReader()
SearchResults.DataSource = objDR
SearchResults.DataBind()
End Sub
Sub ButtonSearch_Click(sender As Object, e As EventArgs)
SrchResult()
End Sub
Sub Page_Load(sender As Object, e As EventArgs)
End Sub
</script>
<html>
<head>
<body topmargin="0" leftmargin="0">
<form runat="Server">
<asp:textbox cssclass="gbbodynormal" id="frmsearch" runat="server" size="15"></asp:textbox>
<br><asp:button cssclass="gbbodynormal" runat="server" id="searchbutton" text="Search" onclick="buttonsearch_click"></asp:button></div>
<aspataList id="searchresults" horizontalAlign="Center" repeatcolumns="3" cssclass = "gbhead" halign="center" ItemStyle-VerticalAlign="Top" itemstyle-horizontalalign= "Center" ItemStyle-Width = "300" width="100%" repeatlayout="table" runat="server">
<ItemStyle CssClass="dash"></ItemStyle>
<itemtemplate>
<p align="center">
<a href="viewproduct.aspx?pid=<%# DataBinder.Eval(Container.DataItem, ("idProduct"))%>&mcat=<%# DataBinder.Eval(Container.DataItem, ("mastercategory"))%>&id=<%# DataBinder.Eval(Container.DataItem, ("idcategory"))%>">
<asp:Image id="Image1" runat="server" src='<%# DataBinder.Eval(Container.DataItem, ("smallimageurl"))%>'>
</asp:Image></a><br>
<%# DataBinder.Eval(Container.DataItem, ("sku"))%><br>
<b><%# DataBinder.Eval(Container.DataItem, ("description"))%></b><br>
List Price: <%# DataBinder.Eval(Container.DataItem, ("listprice"), "{0:c}")%><br>
<b><font color="#CC0000">Sale Price: <%# DataBinder.Eval(Container.DataItem, ("price"), "{0:c}")%><br></font>
<b><font size="3"></font>
</itemtemplate>
</aspataList>
</div>
</form>
</span>
</body>
</html>