Wondering where I’m going wrong here. I’m page loads but when I click on the search (after I type something in the last name field) it just clocks and clocks.
Here’s my aspx.cs page:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection("SERVER=ServerName;Trusted_Connection=Yes;DATABASE=DBNAME")) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "customerSearchStoredProc"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@lName", lNameTextbox.Text); cmd.Connection = con; SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = cmd; adapter.Fill(ds); } con.Close(); } GridView1.DataSource = ds; GridView1.DataBind(); /*SqlDataAdapter adp = new SqlDataAdapter("customerSearchStoredProc", con); adp.SelectCommand.CommandType = CommandType.StoredProcedure; adp.SelectCommand.Parameters.Add(new SqlParameter("@lName", System.Data.SqlDbType.Text)); //adp.SelectCommand.Parameters.Add(new SqlParameter("@State", System.Data.SqlDbType.Text)); adp.SelectCommand.Parameters["@lName"].Value = lNameTextbox.Text; //adp.SelectCommand.Parameters["@State"].Value = StateTextbox.Text; adp.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind();*/ } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } }
Here’s my aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %> <%@ OutputCache Duration="1" VaryByParam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">
<title>MSS Archive Page</title> </head> <body>
<form id="form1" runat="server">
<asp:Label ID="Label1" Text="Last Name" runat="server" />
<asp:TextBox ID="lNameTextbox" runat="server"></asp:TextBox>
<asp:Label ID="Label2" Text="First Name" runat="server" />
<asp:TextBox ID="fName" runat="server" ></asp:TextBox>
<!-- <asp:Label ID="Label3" Text="Street" runat="server" />
<asp:TextBox ID="Street" runat="server" AutoPostBack="True"></asp:TextBox><br />
<asp:Label ID="Label4" Text="City" runat="server" />
<asp:TextBox ID="City" runat="server" AutoPostBack="True" ></asp:TextBox> -->
<asp:Label ID="Label5" Text="State" runat="server" /> <!-- <asp:TextBox ID="State" runat="server" AutoPostBack="True"></asp:TextBox> -->
<asp:TextBox ID="StateTextbox" runat="server" ReadOnly="True">MA</asp:TextBox>
<asp:Label ID="Label6" Text="Zip" runat="server" />
<asp:TextBox ID="Zip" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" PostBackUrl="~/Default.aspx" Text="Search" OnClick="Button1_Click" /><br />
OR<br />
<asp:Label ID="Label7" Text="Policy" runat="server" />
<asp:TextBox ID="Policy" runat="server"></asp:TextBox>
<asp:Label ID="Label8" Text="Account" runat="server" />
<asp:TextBox ID="Account" runat="server"></asp:TextBox> <br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" OnDataBinding="Button1_Click" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
</asp:GridView>
<br />
</form> </body> </html>
Thanks for the help!
Your databinding is calling the on click.
In the on click you call databind.
To me that looks like a loop going on forever.