views:

1499

answers:

5

hi all,

I have two files named as TimeSheet.aspx.cs and TimSheet.aspx ,code of the file are given below for your reference.

when i build the application im getting error "The name 'GridView1' does not exist in the current context" even thought i have a control with the id GridView1 and i have added the runat="server" as well.

Im not able to figure out what is causing this issue.Can any one figure whats happen here.

Thanks & Regards,

=======================================
TimeSheet.aspx.cs 
=======================================
#region Using directives
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TSMS.Web.UI;
#endregion

public partial class TimeSheets: Page
{   
    protected void Page_Load(object sender, EventArgs e)
    {

        FormUtil.RedirectAfterUpdate(GridView1, "TimeSheets.aspx?page={0}");
        FormUtil.SetPageIndex(GridView1, "page");
        FormUtil.SetDefaultButton((Button)GridViewSearchPanel1.FindControl("cmdSearch"));
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string urlParams = string.Format("TimeSheetId={0}", GridView1.SelectedDataKey.Values[0]);
        Response.Redirect("TimeSheetsEdit.aspx?" + urlParams, true);
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) {


    }
}
=======================================================
TimeSheet.aspx
=======================================================
<%@ Page Language="C#" Theme="Default" MasterPageFile="~/MasterPages/admin.master" AutoEventWireup="true"  CodeFile="TimeSheets.aspx.cs" Inherits="TimeSheets" Title="TimeSheets List" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">Time Sheets List</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <data:GridViewSearchPanel ID="GridViewSearchPanel1" runat="server" GridViewControlID="GridView1" PersistenceMethod="Session" />
        <br />
        <data:EntityGridView ID="GridView1" runat="server"          
                AutoGenerateColumns="False"                 
                OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                DataSourceID="TimeSheetsDataSource"
                DataKeyNames="TimeSheetId"
                AllowMultiColumnSorting="false"
                DefaultSortColumnName="" 
                DefaultSortDirection="Ascending"    
                ExcelExportFileName="Export_TimeSheets.xls" onrowcommand="GridView1_RowCommand"         
            >
            <Columns>
                <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />              
                <asp:BoundField DataField="TimeSheetId" HeaderText="Time Sheet Id" SortExpression="[TimeSheetID]" ReadOnly="True" />
                <asp:BoundField DataField="TimeSheetTitle" HeaderText="Time Sheet Title" SortExpression="[TimeSheetTitle]"  />
                <asp:BoundField DataField="StartDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Start Date" SortExpression="[StartDate]"  />
                <asp:BoundField DataField="EndDate" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="End Date" SortExpression="[EndDate]"  />
                <asp:BoundField DataField="DateOfCreation" DataFormatString="{0:d}" HtmlEncode="False" HeaderText="Date Of Creation" SortExpression="[DateOfCreation]"  />
                <data:BoundRadioButtonField DataField="Locked" HeaderText="Locked" SortExpression="[Locked]"  />
                <asp:BoundField DataField="ReviewedBy" HeaderText="Reviewed By" SortExpression="[ReviewedBy]"  />
                <data:HyperLinkField HeaderText="Employee Id" DataNavigateUrlFormatString="EmployeesEdit.aspx?EmployeeId={0}" DataNavigateUrlFields="EmployeeId" DataContainer="EmployeeIdSource" DataTextField="LastName" />

            </Columns>
            <EmptyDataTemplate>
                <b>No TimeSheets Found!</b>
            </EmptyDataTemplate>
        </data:EntityGridView>
        <asp:GridView ID="GridView2" runat="server">
    </asp:GridView>
        <br />
        <asp:Button runat="server" ID="btnTimeSheets" OnClientClick="javascript:location.href='TimeSheetsEdit.aspx'; return false;" Text="Add New"></asp:Button>
        <data:TimeSheetsDataSource ID="TimeSheetsDataSource" runat="server"
            SelectMethod="GetPaged"
            EnablePaging="True"
            EnableSorting="True"
            EnableDeepLoad="True"
            >
            <DeepLoadProperties Method="IncludeChildren" Recursive="False">
                <Types>
                    <data:TimeSheetsProperty Name="Employees"/> 
                    <%--<data:TimeSheetsProperty Name="TimeSheetDetailsCollection" />--%>
                </Types>
            </DeepLoadProperties>
            <Parameters>
                <data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />
                <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
                <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />
                <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />
                <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
            </Parameters>
        </data:TimeSheetsDataSource>

</asp:Content>
+1  A: 

Assuming a WebSite project verify that when building it you do not get Warnings like:

Generation of designer file failed: [Failure Reason]

It seems that you're not registering the custom control EntityGridView. See the Register directive to see how you can do it.

João Angelo
i have done this in web.config, this should take about registering.<controls> <add tagPrefix="data" namespace="TSMS.Web.Data" assembly="TSMS.Web"/> <add tagPrefix="data" namespace="TSMS.Web.UI" assembly="TSMS.Web"/> </controls>
sameer
Did you check Error List for warnings after a clean build of the solution?
João Angelo
A: 

Problem can be that GridView1 is not automatically added in designer.cs file. If that is case add it in designer manually.

SonOfOmer
I Converted to web project, IDE then created designer.cs, it is working now thanks.
sameer
A: 

It is nested, so some things don't happen automatically.

  1. You might have to manually add it to the designer, or else (in VB) explicitly use the handles keyword or (in C#) explicitly wire up with "+=" operator.
  2. Make sure all events or explicitly stated in the control mark-up

Since I see you list the event explicitly, I'd check the designer.

Patrick Karcher
Hi,I don't have the designer file created.how shall i create one.I got this code generated using .nettier template using codesmith code generator.
sameer
In your solution search for "'''GridView1 control.", and hopefully TimeSheets.designer.aspx.cs. Yeah, sometimes the IDE doesn't want to let you get to it easily for some reason.
Patrick Karcher
A: 

I had this same problem in Visual Studio 2010. The design.cs file was correctly generated. I closed Visual Studio, and reopened it. This resolved this issue for me (after much frustration).

Ben Liyanage
A: 

I don't know if this will help, but I've been fighting with a similar situation.

The situation: I have included some code from the modified some of the templated asp.net web project into my project - specifically the login markup. For some reason, one of the "UserName" Textbox control refuses to be recognized in the designer. Strangely enough, the "UserNameLabel" control on the next line of markup is recognized:

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="Logon.aspx.cs" MasterPageFile="~/Site.master" Inherits="SimpleWebApp.Logon" %>

<asp:Content ID="LogonRegister" ContentPlaceHolderID="MainContent" runat="server">
     <div></div>
        <table align="center">
        <tr>
            <td valign="top">
                 *<asp:TextBox ID="TextBox1" runat="server" CssClass="textEntry"></asp:TextBox>*
                 <asp:Login ID="LoginUser" runat="server" EnableViewState="true" RenderOuterTable="false">
                    <LayoutTemplate>
                        <span class="failureNotification">
                            <asp:Literal ID="FailureText" runat="server"></asp:Literal>
                        </span>
                        <asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"/>
                        <div class="accountInfo">
                            <fieldset class="login">
                                <legend>Log In</legend>
                                <p>
                                    **<asp:Label ID="lblUserNameLabel" runat="server">Username:</asp:Label>**
                                    ***<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>***
                                </p>
...

What I've tried: I've restarted VWD 2010, deleted the designer file and recreated it through converting the page to a web application changed the name of the Textbox, deleted and recreated the Textbox.

I decided to experiment a little, and discovered that adding a typical textbox just outside the asp:Login tag is recognized, while adding it just inside that tag leaves it unrecognized in the designer.

Figured this might help myself or someone else to piece together what might be going on.

Anyone have any idea what might cause this behavior around the asp:Login tag?

Thotman