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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird Behavior of ASP.NET!

Status
Not open for further replies.

asafblasberg

Programmer
Jun 22, 2004
21
US
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>


<asp:DataList 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>

</asp:DataList>

</div>
</form>
</span>
</body>
</html>
 
Seems to work for me :)

However, this is a known problem with asp.net. There's no such thing as explicitly setting default buttons for textboxes on the server side (to my knowledge anyways...). You can however set default buttons with javascript.

My suggestion would be, instead of re-inventing the wheel, use Andy's Metabuilders default buttons control:


Hope that helps.

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top