Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having some trouble with my build. For some reason when I added my update panel tool my webpage it will not build what am I missing?

 <%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Customers.aspx.cs" Inherits="Customers" %>
<%@ MasterType VirtualPath="~/Site.master" %>

<asp:Content ID="Content2" ContentPlaceHolderID="cphTitle" runat="server">
    <title>iHelp Customer Data  -- Student ID#(0384348)</title>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" Runat="Server">
    <div id="custTab">
        <asp:Button ID="btnAddNewCustomer" runat="server" Text="Add New Customer" onclick="btnAddNewCustomer_Click" /><br />
        <asp:Label ID="lblConnectionResults" runat="server" Text=""></asp:Label>
    </div>
    <div id="searchLeft">
        Search Customers:<asp:TextBox ID="txtSearch" runat="server" /><asp:Button ID="btnSearch" runat="server" Text="Search" />
    <br />
    </div>
 <asp:UpdatePanel ID="udpCustomer" runat="server">
    <asp:ListView ID="lvCustomers" runat="server">
        <LayoutTemplate>
            <table class="datatable">
                <thead>
                    <th>Customer Name</th>
                    <th>Email</th>
                    <th>City</th>
                    <th>State</th>
                    <th>Phone</th>
                    <th>Modify</th>
                </thead>
                <tr id="itemPlaceHolder"  runat="server"></tr>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td><%# Eval ("Customer Name") %></td>
                <td><%# Eval ("Email") %></td>
                <td><%# Eval ("City")  %></td>
                <td><%# Eval ("State") %></td>
                <td><%# Eval ("Phone") %></td>
                <td><asp:HyperLink ID="lnkEdit" runat="server" NavigateUrl='<%# "CustomerEdit.aspx?Mode=Edit&ID=" + Eval("CustomerID")  %>' Text="Edit" /> <asp:HyperLink ID="lnkDelete" runat="server" NavigateUrl='<%# "ConfirmDelete.aspx?Type=Cust&ID=" + Eval("CustomerID")  %>' Text="Delete" /></td>
            </tr>
        </ItemTemplate>
        
    </asp:ListView>
  </asp:UpdatePanel>
</asp:Content>
Posted
Comments
Prosan 2-Jun-12 2:29am    
what error coming show it.

It should Help you
XML
<asp:UpdatePanel ID="udpCustomer" runat="server">
<Contenttemplate>
    <asp:ListView ID="lvCustomers" runat="server">
        <LayoutTemplate>
            <table class="datatable">
                <thead>
                    <th>Customer Name</th>
                    <th>Email</th>
                    <th>City</th>
                    <th>State</th>
                    <th>Phone</th>
                    <th>Modify</th>
                </thead>
                <tr id="itemPlaceHolder"  runat="server"></tr>
            </table>
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td><%# Eval ("Customer Name") %></td>
                <td><%# Eval ("Email") %></td>
                <td><%# Eval ("City")  %></td>
                <td><%# Eval ("State") %></td>
                <td><%# Eval ("Phone") %></td>
                <td><asp:HyperLink ID="lnkEdit" runat="server" NavigateUrl='<%# "CustomerEdit.aspx?Mode=Edit&ID=" + Eval("CustomerID")  %>' Text="Edit" /> <asp:HyperLink ID="lnkDelete" runat="server" NavigateUrl='<%# "ConfirmDelete.aspx?Type=Cust&ID=" + Eval("CustomerID")  %>' Text="Delete" /></td>
            </tr>
        </ItemTemplate>

    </asp:ListView>
</Contenttemplate>
  </asp:UpdatePanel>
 
Share this answer
 
v2
Comments
[no name] 2-Jun-12 1:53am    
You miss contenttemplate
I'm getting a exception when my code runs. below is the error to my problem.

C#
System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=App_Web_31dpeqc2
  StackTrace:
       at Customers.Page_Load(Object sender, EventArgs e) in f:\Aj's Documents\CPDM\IT-5284 ASP.NET\ASP Website\Customers.aspx.cs:line 38
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 


Below is the page that generated that error. The error comes when the page loads. The exception error occurs in under the page_load at the lvCustomers.DataSource = dt;

Before putting the updatepanel everything worked correctly now I'm getting this error. What I want the page to do is update only the data table when something is put into the txtSearch box onClick of the Search button.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Customers : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      //Create and open connection to database
        SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);

        Conn.Open();

        //Query to pick the data
        string sql = "SELECT LastName + ', ' + FirstName AS 'Customer Name',Email,City,State,Phone, CustomerID FROM Customer ORDER BY LastName, FirstName";

        //Sql Adapter
        SqlDataAdapter da = new SqlDataAdapter(sql, Conn);
            
        //Declare a data table
        DataTable dt = new DataTable();
    
        //Populate the data table
        da.Fill(dt);
    
        //Bind the listview   -->>Error is occuring here onload<<--
        lvCustomers.DataSource = dt;
        lvCustomers.DataBind();

        dt.Dispose();
        Conn.Close();
        da.Dispose();

    }
    protected void btnAddNewCustomer_Click(object sender, EventArgs e)
    {
        Response.Redirect("CustomerEdit.aspx?Mode=New");
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

        string stext = txtSearch.Text;

        //Declare server connection
        SqlConnection Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);

        //Open Database
        Conn.Open();

        //Define the lookup query
        string sql = "SELECT * FROM CUSTOMER WHERE FirstName LIKE '%@stext%' OR LastName LIKE '%@stext%' OR City LIKE '%@stext%' OR State LIKE '%@stext%'";

        //Declare the command
        SqlCommand cmd = new SqlCommand(sql, Conn);

        //Add the parameters needed for the SQL Query
        cmd.Parameters.AddWithValue("@stext", stext);

        //Sql Adapter
        SqlDataAdapter da = new SqlDataAdapter();

        //Declare a data table
        DataTable dt = new DataTable();
        da.SelectCommand = cmd;

      
        //Populate the data table
        da.Fill(dt);

        lblConnectionResults.Text = sql;

        //Bind the listview
        lvCustomers.DataSource = dt;
        lvCustomers.DataBind();

        dt.Dispose();
        Conn.Close();
        da.Dispose();
        



    }
}
 
Share this answer
 
You are missing ContentTemplate tag inside of Update Panel

It should be like this.

XML
<asp:UpdatePanel>
 <ContentTemplate></ContentTemplate>
 </asp:UpdatePanel>



Thanks,
Lijo
 
Share this answer
 
Comments
Anthony Bond 3-Jun-12 23:09pm    
I added the update panel and the contentTemplate my problem I'm having now has to deal with the page_load it throughs a exception saying I need to use the new object. The error is above attached to that is the actual backend to the page.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900