名称为“控制”并不在当前上下文中存在 [英] The name 'control' does not exist in the current context

查看:249
本文介绍了名称为“控制”并不在当前上下文中存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对我的工作,我已经继承的,一旦抓住从资源库和建筑的源网站上有错误的麻烦,然后清除了几个引用错误,我仍然得到了1000这个实例错误:

名称'pnlDetails'不在当前情况下存在(与任何我控制的名字替换'panelDetails')

这是什么似乎表明的是引用的服务器端控件未声明的页面上,或者没有RUNAT =服务器在其中,但实际上他们做的。它也可能是属性不匹配的继承的一个问题,但它确实。我已搜查计算器和之前看到了这个问题,虽然尝试一些提到的解决方案后,他们并没有帮助。我没有任何设计文件我的网页。下面是从ASPX和aspx.cs页面code的一些片段。 (节录了一些信息,以保护客户隐私)

我的问题是,我为什么不能引用在服务器端控制我? paneldetails','rpAddresses等等?

Default.aspx的:

 <%@页标题=LANGUAGE =C#的MasterPageFile =〜/ org.masterAutoEventWireup =真codeFILE =Default.aspx的。 CS继承=directory_Default%GT;<%@注册大会=System.Web.Entity,版本= 3.5.0.0,文化=中性公钥= XXXX
    命名空间=System.Web.UI.WebControls标签preFIX =ASP%GT;
<%@注册标签preFIX =NU命名空间=Leap.NuCaptcha大会=leapmarketing%GT;< ASP:内容ID =内容1ContentPlaceHolderID =cphHead=服务器>
    <标题> XXXX< /标题>
< / ASP:内容>
< ASP:内容ID =内容2ContentPlaceHolderID =cphBreadCrumb=服务器>
    < D​​IV ID =breadCrumbFrame>< A HREF =htt​​p://www.org.org称号=XXX>家庭和LT; / A> &放大器; GT; < A HREF =/目录称号=XXX> XXX和LT; / A>< / DIV>
< / ASP:内容>
< ASP:内容ID =Content3ContentPlaceHolderID =cphBody=服务器>
    < H3类=sectionTitle>&安培; NBSP;&XXX放大器; NBSP;< / H3 GT&;    <! - ////////////开始搜索框面板//////////// - >
    < ASP:面板ID =pnlSearchbox可见=真=服务器DefaultButton =lnkSearch>
        < D​​IV CLASS =信息>
            XXX< A HREF =htt​​p://www.org.org目标=_空白的风格=文字修饰:强调> XXX和LT; / a取代。
        < / DIV>
        < H3风格=填充底:10px的;> XXX:其中; / H3 GT&;
        &所述p为H.; XXX和下; A HREF =htt​​p://www.org.org/> XXX和下; /一个方式>&下; / P>
        < BR />
        < BR />
        < D​​IV CLASS =addressLine>
            < ASP:标签ID =lblFirstName的CssClass =addressLabel=服务器文本=名>< / ASP:标签>
            < ASP:文本框ID =txtFirstName的CssClass =addressEdit=服务器>< / ASP:文本框>
        < / DIV>
        < D​​IV CLASS =addressLine>
            < ASP:标签ID =lblLastName的CssClass =addressLabel=服务器文本=姓>< / ASP:标签>
            < ASP:文本框ID =txtLastName的CssClass =addressEdit=服务器>< / ASP:文本框>
        < / DIV>
        < D​​IV CLASS =addressLine>
            < ASP:标签ID =lblCity的CssClass =addressLabel=服务器文本=城与GT;< / ASP:标签>
            < ASP:文本框ID =txtCity的CssClass =addressEdit=服务器>< / ASP:文本框>
        < / DIV>
        < D​​IV CLASS =addressLine>
            < ASP:标签ID =lblDistrict的CssClass =addressLabel=服务器文本=区>< / ASP:标签>
            < ASP:DropDownList的ID =ddlDistrict的CssClass =addressDropDown=服务器的DataSourceID =dsDistricts
                DataTextField =名称DataValueField =DistrictID
                AppendDataBoundItems =真>
                < ASP:ListItem的值=>所有地区< / ASP:ListItem的>
            < / ASP:DropDownList的>
        < / DIV>
        < D​​IV CLASS =addressLine>
            < ASP:标签ID =lblSpecialty的CssClass =addressLabel=服务器文本=特色>< / ASP:标签>
            < ASP:DropDownList的ID =ddlSpecialty的CssClass =addressDropDown=服务器
                的DataSourceID =dsSpecialtiesDataTextField =xxx_certification
                DataValueField =QualificationIDAppendDataBoundItems =真>
                < ASP:ListItem的值=>所有XXX< / ASP:ListItem的>
            < / ASP:DropDownList的>
        < / DIV>
        < D​​IV CLASS =addressLine>
            < D​​IV CLASS =addressLabel>&安培; NBSP;< / DIV>
            < ASP:LinkBut​​ton的ID =lnkSearch的CssClass =navButton=服务器
                的onclick =lnkSearch_Click>搜索和LT; / ASP:LinkBut​​ton的>
        < / DIV>
    < / ASP:面板>
    < ASP:使用LinqDataSource ID =dsDistricts=服务器
        ContextTypeName =org.Xrm.XrmDataContext选择=新的(DistrictID,名称)
        表名=区>
    < / ASP:使用LinqDataSource>
    < ASP:使用LinqDataSource ID =dsSpecialties=服务器
        ContextTypeName =org.Xrm.XrmDataContext
        选择=新的(QualificationID,xxx_certification)表名=资格
        凡=EducationTypeID == @EducationTypeID>
        < whereparameters>
            < ASP:参数默认值=000NAME =EducationTypeID
                的DbType =GUID/>
        < / whereparameters>
    < / ASP:使用LinqDataSource>    <! - ////////////开始搜索结果面板//////////// - >    < ASP:面板ID =pnlResults可见=假=服务器>
        < D​​IV ID =ResultsTop的风格=保证金底:15px的;>
            < D​​IV ID =ResultsLeft的风格=浮动:左;填充顶:5像素;>
                < H2>搜索结果 - <跨度类=BlackResults>
                    < ASP:标签ID =lblCount=服务器文本=>< / ASP:标签>< / SPAN>< / H>
            < / DIV>
        < / DIV>
        < BR />
        < BR />
        < BR />
        < ASP:LinkBut​​ton的ID =lnkNewSearch的CssClass =navButtonLarge=服务器的OnClick =lnkNewSearch_Click>全新搜索< / ASP:LinkBut​​ton的>
        < BR />
        < BR />
        < D​​IV ALIGN =中心>
            < ASP:DataPager的ID =DataPager2=服务器PagedControlID =lvResults
                每页=25>
                <&领域GT;
                    < ASP:接下来previousPagerField ShowFirstPageButton =真
                        ShowNextPageButton =FALSE显示previousPageButton =真/>
                    < ASP:NumericPagerField ButtonCount =10/>
                    < ASP:接下来previousPagerField ShowLastPageButton =真
                        ShowNextPageButton =真显示previousPageButton =FALSE/>
                < /田>
            < / ASP:DataPager的>
        < / DIV>
        < BR />
        < ASP:ListView控件ID =lvResults=服务器的DataSourceID =dsSearchResults>
            <&ItemTemplate中GT;
                < TR风格=>
                    < TD类=DirectoryItems>
                        < ASP:LinkBut​​ton的ID =lnkDetailsCommandArgument ='<%#的eval(ID)%GT;'按需=lnkDetails_Click=服务器><%#的eval(XXX)%GT;< / ASP:LinkBut​​ton的>
                    < / TD>
                    < TD类=DirectoryItems>
                        < ASP:标签ID =LocationLabel=服务器文本='<%#的eval(位置)%GT;' />
                    < / TD>
                    < TD类=DirectoryItems>
                        < ASP:标签ID =StatusLabel=服务器文本='<%#的eval(状态)%GT;' />
                    < / TD>
                < / TR>
            < / ItemTemplate中>
            < emptydatatemplate>
                <表=服务器的风格=>
                    &所述; TR>
                        &所述; TD>
                            没有数据被送回< / TD>
                    < / TR>
                < /表>
            < / emptydatatemplate>
            <&LayoutTemplate模板GT;
                <表=服务器WIDTH =100%>
                    < TR =服务器>
                        < TD =服务器>
                            <表ID =itemPlaceholderContainer=服务器BORDER =0的风格=边界崩溃:崩溃; WIDTH =99%>
                                < TR =服务器的风格=BORDER-底:1px的固体#828283;的margin-top:5像素;保证金底:为5px;填充顶:5像素;填充底:为5px;>
                                    < TD =服务器WIDTH =40%>
                                        < p =类DirectoryResultsHeader> XXX和LT; / P>< / TD>
                                    < TD =服务器WIDTH =30%>
                                        < p =类DirectoryResultsHeader>位置和LT; / P>< / TD>
                                    < TD =服务器WIDTH =30%>
                                        < p =类DirectoryResultsHeader>状态和LT; / P>< / TD>
                                < / TR>
                                < TR ID =itemPlaceholder=服务器>
                                < / TR>
                            < /表>
                        < / TD>
                    < / TR>
                    < TR =服务器>
                        < TD =服务器的风格=>
                        < / TD>
                    < / TR>
                < /表>
            < / LayoutTemplate模板>
        < / ASP:的ListView>
        < BR />
        < BR />
        < D​​IV ALIGN =中心>
            < ASP:DataPager的ID =DataPager1=服务器PagedControlID =lvResults
                每页=25>
                <&领域GT;
                    < ASP:接下来previousPagerField ShowFirstPageButton =真
                        ShowNextPageButton =FALSE显示previousPageButton =真/>
                    < ASP:NumericPagerField ButtonCount =10/>
                    < ASP:接下来previousPagerField ShowLastPageButton =真
                        ShowNextPageButton =真显示previousPageButton =FALSE/>
                < /田>
            < / ASP:DataPager的>
        < / DIV>
        < ASP:SqlDataSource的ID =dsSearchResults=服务器OnSelected =dsSearchResults_Selected
            的ConnectionString =<%$的ConnectionStrings:MSCRM%>中CancelSelectOnNullParameter =假
            的SelectCommand =
                        从sometable SELECT *
            >
            < selectparameters>
                    < ASP:ControlParameter控件ID =txtFirstName的DbType =字符串名称=名字默认值=ConvertEmptyStringToNull =FALSE/>
                    < ASP:ControlParameter控件ID =txtLastName的DbType =字符串名称=姓氏默认值=ConvertEmptyStringToNull =FALSE/>
                    < ASP:ControlParameter控件ID =txtCity的DbType =字符串NAME =城默认值=ConvertEmptyStringToNull =FALSE/>
                    < ASP:ControlParameter控件ID =ddlDistrict的DbType =GUIDNAME =区ConvertEmptyStringToNull =真/>
                    < ASP:ControlParameter控件ID =ddlSpecialty的DbType =GUIDNAME =特色ConvertEmptyStringToNull =真/>
                < / selectparameters>
        < / ASP:SqlDataSource的>
    < / ASP:面板>    <! - ////////////开始详细信息面板//////////// - >    < ASP:面板ID =pnlDetails可见=假=服务器>
        < H3> XXX信息与LT; / H3 GT&;
        < BR />
        < ASP:直放站ID =rpDetails=服务器的DataSourceID =dsDetails>
            <&ItemTemplate中GT;
                <表格边框=0>
                    &所述; TR>
                        < TD WIDTH =125>< B>给定的名称:LT; / B>< / TD>
                        < TD><%#的eval(名字)%>< / TD>
                    < / TR>
                    &所述; TR>
                        < TD WIDTH =125>< B>姓氏:其中; / B>< / TD>
                        < TD><%#的eval(姓氏)%GT;< / TD>
                    < / TR>
                    &所述; TR>
                        < TD WIDTH =125>< B>性别:LT; / B>< / TD>
                        < TD><%#的eval(性别)%GT;< / TD>
                    < / TR>
                    &所述; TR>
                        < TD WIDTH =125>< B>状态:其中; / B>< / TD>
                        < TD><%#的eval(状态)%GT;< / TD>
                    < / TR>
                    < ASP:面板ID =pnlSpecialty=服务器可见='<%#的eval(状态)的ToString()==XXX||。的eval(状态)的ToString()==XXX||的eval(状态)的ToString()==XXX?真:假%GT;'>
                        &所述; TR>
                            < TD WIDTH =125>< B> XXX:其中; / B>< / TD>
                            &所述; TD>
                                < ASP:直放站ID =XXX=服务器的DataSourceID =XXX>
                                    <&ItemTemplate中GT;
                                        <%#的eval(XXX)%GT;< BR />
                                    < / ItemTemplate中>
                                < / ASP:直放站>
                            < / TD>
                        < / TR>
                    < / ASP:面板>
                    &所述; TR>
                        < TD WIDTH =125>< B> XXX:其中; / B>< / TD>
                        < TD><%#的eval(XXX)%GT;< / TD>
                    < / TR>
                < /表>
            < / ItemTemplate中>
        < / ASP:直放站>
        < BR />
        < BR />
        < ASP:直放站ID =rpAddresses=服务器的DataSourceID =dsAddressesOnItemDataBound =rpAddresses_DataBound>
            <&HeaderTemplate中GT;
                < H3> XXX和LT; / H3和GT;< BR />
            < / HeaderTemplate中>
            <&ItemTemplate中GT;
                <表格边框=0>
                    &所述; TR>
                        < TD VALIGN =顶WIDTH =125>< B>< ASP:标签ID =lblAddressType=服务器文本='<%#的eval(类型)%> />< / B>< / TD>
                        < TD VALIGN =顶>
                            < ASP:标签ID =lblAddressStreet1=服务器文本='<%#的eval(Street1)+< BR />中%GT;'可见='<%#Convert.IsDBNull(EVAL(Street1))?假:真的%GT;' />
                            < ASP:标签ID =lblAddressStreet2=服务器文本='<%#的eval(STREET2)+< BR />中%GT;'可见='<%#Convert.IsDBNull(EVAL(STREET2))?假:真的%GT;' />
                            < ASP:标签ID =lblAddressStreet3=服务器文本='<%#的eval(Street3)+< BR />中%GT;'可见='<%#Convert.IsDBNull(EVAL(Street3))?假:真的%GT;' />
                            < ASP:标签ID =lblAddressCity=服务器文本='<%#的eval(城市)%GT;' />中< ASP:标签ID =lblAddressProvince=服务器文本='<%#的eval(省)%>' />&安培; NBSP;&安培; NBSP;< ASP:标签ID =lblAddressPostal code=服务器文本='<%#的eval(邮政code)%> />< BR />
                            < ASP:标签ID =lblAddressCountry=服务器文本='<%#的eval(国家)+< BR />中%GT;'可见='<%#(的eval(国家,{0})==加拿大)?假:真的%GT;' />
                            <表格边框=0>
                                < ASP:标签ID =lblAddressPhone=服务器文本='<%#< TR>< TD宽度= 50>电话:< / TD>< TD>中+的eval(手机)+< / TD>< / TR>中%GT;'可见='<%#Convert.IsDBNull(EVAL(手机))?假:真的%GT;' />
                                < ASP:标签ID =lblAddressFax=服务器文本='<%#< TR>< TD宽度= 50>传真:LT; / TD>< TD>中+的eval(传真)+< / TD>< / TR>中%GT;'可见='<%#Convert.IsDBNull(EVAL(传真))?假:真的%GT;' />
                                < ASP:占位符ID =cphEmailAddress=服务器可见='<%#Convert.IsDBNull(EVAL(电子邮件))?假:真的%GT;'>< TR>< TD WIDTH =50>电子邮件:< / TD>< TD>< ASP:LinkBut​​ton的ID =lnkEmailValidate=服务器文本='<%#的eval(ShortEmail)%>'的OnClick =ShowReCAPTCHA/>< / TD>< / TR>< / ASP:占位符>
                                < ASP:占位符ID =cphEmail=服务器可见=假>< TR>< TD WIDTH =50>电子邮件:< / TD>< TD>< ASP :超链接ID =lnkEmail=服务器NavigateUrl ='<%#的eval(电子邮件,电子邮件地址:{0})%GT;'文字='<%#的eval(电子邮件)%>' />< / TD>< / TR>< / ASP:占位符>
                             < /表>
                             < ASP:占位符ID =cphCaptcha=服务器可见=假>
                                   < BR />
                                    < D​​IV CLASS =信息>向查看完整的电子邮件地址,请键入下面的方框中移动人物< / DIV>
                    < NU:NuCaptchaControl ID =nucaptcha=服务器ClientKey =LEAP | 0 | 4 |类型| 9 | CLIENTKEY | CID | 4 | 9942 |童装| 4 | 9884 | SKEY | 32 | bDdiOWgwdjhtNy1MdTRENG43Q1BZdyws/&GT ;                             < / ASP:占位符>
                        < / TD>
                    < / TR>
                < /表>
                < BR />            < / ItemTemplate中>
        < / ASP:直放站>
        < BR />
        < BR />
        < ASP:LinkBut​​ton的ID =lnkDetailsBack的CssClass =navButtonLarge=服务器的OnClick =lnkDetailsBack_Click>返回搜索结果片剂; / ASP:LinkBut​​ton的>
        < ASP:LinkBut​​ton的ID =lnkDetailsNewSearch=服务器的CssClass =navButtonLarge的OnClick =lnkNewSearch_Click>全新搜索< / ASP:LinkBut​​ton的>
        < ASP:SqlDataSource的ID =dsDetails=服务器
            的ConnectionString =<%$的ConnectionStrings:MSCRM%>中
            的SelectCommand =
                        一些表的SELECT *
            >
            < selectparameters>
                    < ASP:参数的DbType =GUIDNAME =的ContactID/>
                < / selectparameters>
        < / ASP:SqlDataSource的>
        < ASP:SqlDataSource的ID =dsSpecialty=服务器
            的ConnectionString =<%$的ConnectionStrings:MSCRM%>中
            的SelectCommand =
                        一些表的SELECT *
            >
            < selectparameters>
                    < ASP:参数的DbType =GUIDNAME =的ContactID/>
                < / selectparameters>
        < / ASP:SqlDataSource的>
        < ASP:SqlDataSource的ID =dsAddresses=服务器
            的ConnectionString =<%$的ConnectionStrings:XXX%>中
            的SelectCommand =
                        一些表的SELECT *
            >
            < selectparameters>
                    < ASP:参数的DbType =GUIDNAME =的ContactID/>
                < / selectparameters>
        < / ASP:SqlDataSource的>
    < / ASP:面板>    <! - ////////////开始数据源//////////// - >< / ASP:内容>

default.aspx.cs

 使用系统;
使用System.Data这;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;公共部分类directory_Default:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        如果(Page.IsPostBack&放大器;&放大器; pnlDetails.Visible ==真放大器;&放大器; rpAddresses.Items.Count大于0&放大器;及((占位符)rpAddresses.Items [0] .FindControl(cphCaptcha))。可见== true)而
        {
            Page.Validate();
            如果(Page.IsValid)
            {
                ((预留)rpAddresses.Items [0] .FindControl(cphCaptcha))可见=假。
                ((预留)rpAddresses.Items [0] .FindControl(cphEmailAddress))可见=假。
                ((预留)rpAddresses.Items [0] .FindControl(cphEmail))可见=真。
            }
        }
    }    保护无效rpAddresses_DataBound(对象发件人,EventArgs的发送)
    {
    }    保护无效lnkSearch_Click(对象发件人,EventArgs的发送)
    {
        //lvResults.DataBind();
        DataPager1.SetPageProperties(0,DataPager1.PageSize,真);
        显示结果();
    }    保护无效ShowResults()
    {
        pnlSearchbox.Visible = FALSE;
        pnlResults.Visible =真;
        pnlDetails.Visible = FALSE;
    }    保护无效lnkNewSearch_Click(对象发件人,EventArgs的发送)
    {
        pnlSearchbox.Visible =真;
        pnlResults.Visible = FALSE;
        pnlDetails.Visible = FALSE;
    }    保护无效lnkDetails_Click(对象发件人,CommandEventArgs E)
    {
        dsDetails.SelectParameters [的ContactID] =默认值e.CommandArgument.ToString()。
        dsSpecialty.SelectParameters [的ContactID] =默认值e.CommandArgument.ToString()。
        dsAddresses.SelectParameters [的ContactID] =默认值e.CommandArgument.ToString()。
        rpAddresses.DataBind();
        如果(rpAddresses.Items.Count == 0)
        {
            rpAddresses.Visible = FALSE;
        }
        其他
        {
            rpAddresses.Visible = TRUE;
        }
        pnlSearchbox.Visible = FALSE;
        pnlResults.Visible = FALSE;
        pnlDetails.Visible =真;
    }    保护无效lnkDetailsBack_Click(对象发件人,EventArgs的发送)
    {
        显示结果();
    }    保护无效dsSearchResults_Selected(对象发件人,SqlDataSourceStatusEventArgs E)
    {
        lblCount.Text =的String.Format({0}牙医发现,e.AffectedRows);
    }    保护无效ShowReCAPTCHA(对象发件人,EventArgs的发送)
    {
        ((预留)rpAddresses.Items [0] .FindControl(cphCaptcha))可见=真。
    }
}


解决方案

感谢您的答案的人,我也尝试了一些这些事情。


  

      
  1. 您希望在aspx.cs访问每个控件应该有=服务器

  2.   

他们做


  <醇开始=2>
  
  • 添加上述标记之后构建解决方案


  •   
  • 如果您要访问中继器的项目模板中定义的控制你
      可以在里面转发的事件通过把一个循环读取所以只有做
      中继器的所有项目


  •   

    他们


      

    右键点击页面你在哪里得到的错误,然后点击
      转换成Web应用程序...这将解决您的错误。


    在我的IDE没有这样的选择,况且我认为这将是整个项目,不是我转换页面。


      

    检查是否这是一个Web应用程序项目或网站
      项目。网站项目将使用的的codeFILE属性
      @ Page指令,而是一个Web应用程序项目不会。如果它是
      尝试编译为Web应用程序项目,您将收到
      这些错误,因为Web应用程序项目预计设计师文件
      除了在.aspx和.aspx.cs文件。设计师包含了所有
      对照定义,从而允许您参考
      他们在正确的codebehind(Web应用程序使用codeBehind而不是
      codeFILE属性也一样)。


    显然,然后我的项目是一个网站,而不是一个Web应用程序,因为它包含了codeFile的属性。还有,我没有设计文件,因此,这是有道理的。

    原来我试图编辑在VS2008开发,使用VS2013的解决方案,此后便发生了很多变化。虽然没有在这里解决问题,修复是创建一个新的VS2013解决方案,并导入文件,它的所有工作作为目前打算,谢谢你。

    I am having trouble with an error on a site I am working on that I've inherited, upon grabbing the source from the repository and building, then clearing out a few reference errors, I am still getting over 1000 instances of this error:

    The name 'pnlDetails' does not exist in the current context (replace 'panelDetails' with any of my control names).

    what this would seem to indicate is that the controls referenced server side are not declared on the page, or don't have runat=server in them, but in fact they do. it could also be a problem of the inherits attribute not matching, but it does. I have searched stackoverflow and seen this question before, though after trying some of the solutions mentioned, they did not help. I do not have any designer files for my pages. Below are some snippets of code from the aspx and aspx.cs pages. (some information redacted to protect client privacy)

    My question is, why can't i reference my controls on the server side? 'paneldetails', 'rpAddresses' etc.?

    default.aspx:

    <%@ Page Title="" Language="C#" MasterPageFile="~/org.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="directory_Default" %>
    
    <%@ Register Assembly="System.Web.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=xxxx"
        Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>
    <%@ Register TagPrefix="nu" Namespace="Leap.NuCaptcha" Assembly="leapmarketing" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="cphHead" Runat="Server">
        <title>xxxx</title>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="cphBreadCrumb" Runat="Server">
        <div id="breadCrumbFrame"><a href="http://www.org.org" title="xxx">Home</a>  &gt; <a href="/directory" title="xxx">xxx</a></div>
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="cphBody" Runat="Server">
        <h3 class="sectionTitle">&nbsp;xxx&nbsp;</h3>
    
        <!--//////////// Begin Searchbox Panel ////////////-->
        <asp:Panel ID="pnlSearchbox" Visible="true" runat="server" DefaultButton="lnkSearch">
            <div class="info">
                xxx <a href="http://www.org.org" target="_blank" style="text-decoration: underline">xxx</a>.
            </div>
            <h3 style="padding-bottom: 10px;">xxx:</h3>
            <p>xxx <a href="http://www.org.org/">xxx</a>.</p>
            <br />
            <br />
            <div class="addressLine">
                <asp:Label ID="lblFirstName" CssClass="addressLabel" runat="server" Text="First Name"></asp:Label>
                <asp:TextBox ID="txtFirstName" CssClass="addressEdit" runat="server"></asp:TextBox>
            </div>
            <div class="addressLine">
                <asp:Label ID="lblLastName" CssClass="addressLabel" runat="server" Text="Last Name"></asp:Label>
                <asp:TextBox ID="txtLastName" CssClass="addressEdit" runat="server"></asp:TextBox>
            </div>
            <div class="addressLine">
                <asp:Label ID="lblCity" CssClass="addressLabel" runat="server" Text="City"></asp:Label>
                <asp:TextBox ID="txtCity" CssClass="addressEdit" runat="server"></asp:TextBox>
            </div>
            <div class="addressLine">
                <asp:Label ID="lblDistrict" CssClass="addressLabel" runat="server" Text="District"></asp:Label>
                <asp:DropDownList ID="ddlDistrict" CssClass="addressDropDown" runat="server" DataSourceID="dsDistricts"
                    DataTextField="Name" DataValueField="DistrictID"
                    AppendDataBoundItems="True">
                    <asp:ListItem Value="">All Districts</asp:ListItem>
                </asp:DropDownList>
            </div>
            <div class="addressLine">
                <asp:Label ID="lblSpecialty" CssClass="addressLabel" runat="server" Text="Specialty"></asp:Label>
                <asp:DropDownList ID="ddlSpecialty" CssClass="addressDropDown" runat="server"
                    DataSourceID="dsSpecialties" DataTextField="xxx_certification"
                    DataValueField="QualificationID" AppendDataBoundItems="True">
                    <asp:ListItem Value="">All xxx</asp:ListItem>
                </asp:DropDownList>
            </div>
            <div class="addressLine">
                <div class="addressLabel">&nbsp;</div>
                <asp:LinkButton ID="lnkSearch" CssClass="navButton" runat="server"
                    onclick="lnkSearch_Click">Search</asp:LinkButton>
            </div>
        </asp:Panel>
        <asp:LinqDataSource ID="dsDistricts" runat="server"
            ContextTypeName="org.Xrm.XrmDataContext" Select="new (DistrictID, Name)"
            TableName="Districts">
        </asp:LinqDataSource>
        <asp:LinqDataSource ID="dsSpecialties" runat="server"
            ContextTypeName="org.Xrm.XrmDataContext"
            Select="new (QualificationID, xxx_certification)" TableName="Qualifications"
            Where="EducationTypeID == @EducationTypeID">
            <whereparameters>
                <asp:Parameter DefaultValue="000" Name="EducationTypeID" 
                    DbType="Guid" />
            </whereparameters>
        </asp:LinqDataSource>
    
        <!--//////////// Begin Search Results Panel ////////////-->
    
        <asp:Panel ID="pnlResults" Visible="false" runat="server">
            <div id="ResultsTop" style="margin-bottom: 15px;">
                <div id="ResultsLeft" style="float: left; padding-top: 5px;">
                    <h2>Search Results - <span class="BlackResults">
                        <asp:Label ID="lblCount" runat="server" Text=""></asp:Label></span></h2>
                </div>
            </div>
            <br />
            <br />
            <br />
            <asp:LinkButton ID="lnkNewSearch" CssClass="navButtonLarge" runat="server" OnClick="lnkNewSearch_Click">New Search</asp:LinkButton>
            <br />
            <br />
            <div align="center">
                <asp:DataPager ID="DataPager2" runat="server" PagedControlID="lvResults"
                    PageSize="25">
                    <fields>
                        <asp:NextPreviousPagerField ShowFirstPageButton="True" 
                            ShowNextPageButton="False" ShowPreviousPageButton="True" />
                        <asp:NumericPagerField ButtonCount="10" />
                        <asp:NextPreviousPagerField ShowLastPageButton="True" 
                            ShowNextPageButton="True" ShowPreviousPageButton="False" />
                    </fields>
                </asp:DataPager>
            </div>
            <br />
            <asp:ListView ID="lvResults" runat="server" DataSourceID="dsSearchResults">
                <itemtemplate>
                    <tr style="">
                        <td class="DirectoryItems">
                            <asp:LinkButton ID="lnkDetails" CommandArgument='<%# Eval("ID") %>' OnCommand="lnkDetails_Click" runat="server"><%# Eval("xxx") %></asp:LinkButton>
                        </td>
                        <td class="DirectoryItems">
                            <asp:Label ID="LocationLabel" runat="server" Text='<%# Eval("Location") %>' />
                        </td>
                        <td class="DirectoryItems">
                            <asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>' />
                        </td>
                    </tr>
                </itemtemplate>
                <emptydatatemplate>
                    <table runat="server" style="">
                        <tr>
                            <td>
                                No data was returned.</td>
                        </tr>
                    </table>
                </emptydatatemplate>
                <layouttemplate>
                    <table runat="server" width="100%">
                        <tr runat="server">
                            <td runat="server">
                                <table ID="itemPlaceholderContainer" runat="server" border="0" style="border-collapse: collapse;" width="99%">
                                    <tr runat="server" style="border-bottom:1px solid #828283; margin-top:5px; margin-bottom:5px; padding-top:5px; padding-bottom:5px;">
                                        <td runat="server" width="40%">
                                            <p class="DirectoryResultsHeader">xxx</p></td>
                                        <td runat="server" width="30%">
                                            <p class="DirectoryResultsHeader">Location</p></td>
                                        <td runat="server" width="30%">
                                            <p class="DirectoryResultsHeader">Status</p></td>
                                    </tr>
                                    <tr ID="itemPlaceholder" runat="server">
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr runat="server">
                            <td runat="server" style="">
                            </td>
                        </tr>
                    </table>
                </layouttemplate>
            </asp:ListView>
            <br />
            <br />
            <div align="center">
                <asp:DataPager ID="DataPager1" runat="server" PagedControlID="lvResults"
                    PageSize="25">
                    <fields>
                        <asp:NextPreviousPagerField ShowFirstPageButton="True" 
                            ShowNextPageButton="False" ShowPreviousPageButton="True" />
                        <asp:NumericPagerField ButtonCount="10" />
                        <asp:NextPreviousPagerField ShowLastPageButton="True" 
                            ShowNextPageButton="True" ShowPreviousPageButton="False" />
                    </fields>
                </asp:DataPager>
            </div>
            <asp:SqlDataSource ID="dsSearchResults" runat="server" OnSelected="dsSearchResults_Selected"
                ConnectionString="<%$ ConnectionStrings:MSCRM %>" CancelSelectOnNullParameter="false"
                SelectCommand="
                            SELECT * from sometable
                ">
                <selectparameters>
                        <asp:ControlParameter ControlID="txtFirstName" DbType="String" Name="FirstName" DefaultValue="" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter ControlID="txtLastName" DbType="String" Name="LastName" DefaultValue="" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter ControlID="txtCity" DbType="String" Name="City" DefaultValue="" ConvertEmptyStringToNull="false" />
                        <asp:ControlParameter ControlID="ddlDistrict" DbType="Guid" Name="District" ConvertEmptyStringToNull="true" />
                        <asp:ControlParameter ControlID="ddlSpecialty" DbType="Guid" Name="Specialty" ConvertEmptyStringToNull="true" />
                    </selectparameters>
            </asp:SqlDataSource>
        </asp:Panel>
    
        <!--//////////// Begin Details Panel ////////////-->
    
        <asp:Panel ID="pnlDetails" Visible="false" runat="server">
            <h3>xxx Information</h3>
            <br />
            <asp:Repeater ID="rpDetails" runat="server" DataSourceID="dsDetails">
                <itemtemplate>
                    <table border="0">
                        <tr>
                            <td width="125"><b>Given Name:</b></td>
                            <td><%# Eval("FirstName") %></td>
                        </tr>
                        <tr>
                            <td width="125"><b>Surname:</b></td>
                            <td><%# Eval("LastName") %></td>
                        </tr>
                        <tr>
                            <td width="125"><b>Gender:</b></td>
                            <td><%#Eval("Gender") %></td>
                        </tr>
                        <tr>
                            <td width="125"><b>Status:</b></td>
                            <td><%# Eval("Status") %></td>
                        </tr>
                        <asp:Panel ID="pnlSpecialty" runat="server" Visible='<%# Eval("Status").ToString() == "xxx" || Eval("Status").ToString() == "xxx" || Eval("Status").ToString() == "xxx" ? true : false %>'>
                            <tr>
                                <td width="125"><b>xxx:</b></td>
                                <td>
                                    <asp:Repeater ID="xxx" runat="server" DataSourceID="xxx">
                                        <ItemTemplate>
                                            <%# Eval("xxx") %><br />
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </td>
                            </tr>
                        </asp:Panel>
                        <tr>
                            <td width="125"><b>xxx:</b></td>
                            <td><%# Eval("xxx") %></td>
                        </tr>
                    </table>
                </itemtemplate>
            </asp:Repeater>
            <br />
            <br />
            <asp:Repeater ID="rpAddresses" runat="server" DataSourceID="dsAddresses" OnItemDataBound="rpAddresses_DataBound">
                <headertemplate>
                    <h3>xxx</h3><br />
                </headertemplate>
                <itemtemplate>
                    <table border="0">
                        <tr>
                            <td valign="top" width="125"><b><asp:Label ID="lblAddressType" runat="server" Text='<%# Eval("Type") %>' /></b></td>
                            <td valign="top">
                                <asp:Label ID="lblAddressStreet1" runat="server" Text='<%# Eval("Street1") + "<br />" %>' Visible='<%# Convert.IsDBNull(Eval("Street1")) ? false : true %>' />
                                <asp:Label ID="lblAddressStreet2" runat="server" Text='<%# Eval("Street2") + "<br />" %>' Visible='<%# Convert.IsDBNull(Eval("Street2")) ? false : true %>' />
                                <asp:Label ID="lblAddressStreet3" runat="server" Text='<%# Eval("Street3") + "<br />" %>' Visible='<%# Convert.IsDBNull(Eval("Street3")) ? false : true %>' />
                                <asp:Label ID="lblAddressCity" runat="server" Text='<%# Eval("City") %>' />, <asp:Label ID="lblAddressProvince" runat="server" Text='<%# Eval("Province") %>' />&nbsp;&nbsp;<asp:Label ID="lblAddressPostalCode" runat="server" Text='<%# Eval("PostalCode") %>' /><br />
                                <asp:Label ID="lblAddressCountry" runat="server" Text='<%# Eval("Country") + "<br />" %>' Visible='<%# (Eval("Country", "{0}") == "Canada") ? false : true %>' />
                                <table border="0">
                                    <asp:Label ID="lblAddressPhone" runat="server" Text='<%# "<tr><td width=50>Phone:</td><td>" + Eval("Phone") + "</td></tr>" %>' Visible='<%#Convert.IsDBNull(Eval("Phone")) ? false : true %>' />
                                    <asp:Label ID="lblAddressFax" runat="server" Text='<%# "<tr><td width=50>Fax:</td><td>" + Eval("Fax") + "</td></tr>" %>' Visible='<%#Convert.IsDBNull(Eval("Fax")) ? false : true %>' />
                                    <asp:PlaceHolder ID="cphEmailAddress" runat="server" Visible='<%# Convert.IsDBNull(Eval("Email")) ? false : true %>'><tr><td width="50">Email:</td><td><asp:LinkButton ID="lnkEmailValidate" runat="server" Text='<%# Eval("ShortEmail") %>' OnClick="ShowReCAPTCHA" /></td></tr></asp:PlaceHolder>
                                    <asp:PlaceHolder ID="cphEmail" runat="server" Visible="false"><tr><td width="50">Email:</td><td><asp:HyperLink ID="lnkEmail" runat="server" NavigateUrl='<%# Eval("Email", "mailto:{0}") %>' Text='<%# Eval("Email") %>' /></td></tr></asp:PlaceHolder>
                                 </table>
                                 <asp:PlaceHolder ID="cphCaptcha" runat="server" Visible="false">
                                       <br />
                                        <div class="info">To view the full email address, please type the moving characters in the box below.</div>
                        <nu:NuCaptchaControl ID="nucaptcha" runat="server" ClientKey="LEAP|0|4|TYPE|9|CLIENTKEY|CID|4|9942|KID|4|9884|SKEY|32|bDdiOWgwdjhtNy1MdTRENG43Q1BZdyws" />
    
                                 </asp:PlaceHolder>
                            </td>
                        </tr>
                    </table>
                    <br />
    
                </itemtemplate>
            </asp:Repeater>
            <br />
            <br />
            <asp:LinkButton ID="lnkDetailsBack" CssClass="navButtonLarge" runat="server" OnClick="lnkDetailsBack_Click">Back to Search Results</asp:LinkButton>
            <asp:LinkButton ID="lnkDetailsNewSearch" runat="server" CssClass="navButtonLarge" OnClick="lnkNewSearch_Click">New Search</asp:LinkButton>
            <asp:SqlDataSource ID="dsDetails" runat="server"
                ConnectionString="<%$ ConnectionStrings:MSCRM %>"
                SelectCommand="
                            SELECT * from some table
                ">
                <selectparameters>
                        <asp:Parameter DbType="Guid" Name="ContactID" />
                    </selectparameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="dsSpecialty" runat="server"
                ConnectionString="<%$ ConnectionStrings:MSCRM %>"
                SelectCommand="
                            SELECT * from some table 
                ">
                <selectparameters>
                        <asp:Parameter DbType="Guid" Name="ContactID" />
                    </selectparameters>
            </asp:SqlDataSource>
            <asp:SqlDataSource ID="dsAddresses" runat="server"
                ConnectionString="<%$ ConnectionStrings:xxx %>"
                SelectCommand="
                            SELECT * from some table 
                ">
                <selectparameters>
                        <asp:Parameter DbType="Guid" Name="ContactID" />
                    </selectparameters>
            </asp:SqlDataSource>
        </asp:Panel>
    
        <!--//////////// Begin Data Sources ////////////-->
    
    </asp:Content>
    

    default.aspx.cs

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class directory_Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack && pnlDetails.Visible == true && rpAddresses.Items.Count > 0 && ((PlaceHolder)rpAddresses.Items[0].FindControl("cphCaptcha")).Visible == true)
            {
                Page.Validate();
                if (Page.IsValid)
                {
                    ((PlaceHolder)rpAddresses.Items[0].FindControl("cphCaptcha")).Visible = false;
                    ((PlaceHolder)rpAddresses.Items[0].FindControl("cphEmailAddress")).Visible = false;
                    ((PlaceHolder)rpAddresses.Items[0].FindControl("cphEmail")).Visible = true;
                }
            }
        }
    
        protected void rpAddresses_DataBound(object sender, EventArgs e)
        {
        }
    
        protected void lnkSearch_Click(object sender, EventArgs e)
        {
            //lvResults.DataBind();
            DataPager1.SetPageProperties(0, DataPager1.PageSize, true);
            ShowResults();
        }
    
        protected void ShowResults()
        {
            pnlSearchbox.Visible = false;
            pnlResults.Visible = true;
            pnlDetails.Visible = false;
        }
    
        protected void lnkNewSearch_Click(object sender, EventArgs e)
        {
            pnlSearchbox.Visible = true;
            pnlResults.Visible = false;
            pnlDetails.Visible = false;
        }
    
        protected void lnkDetails_Click(object sender, CommandEventArgs e)
        {
            dsDetails.SelectParameters["ContactID"].DefaultValue = e.CommandArgument.ToString();
            dsSpecialty.SelectParameters["ContactID"].DefaultValue = e.CommandArgument.ToString();
            dsAddresses.SelectParameters["ContactID"].DefaultValue = e.CommandArgument.ToString();
            rpAddresses.DataBind();
            if (rpAddresses.Items.Count == 0)
            {
                rpAddresses.Visible = false;
            }
            else
            {
                rpAddresses.Visible = true;
            }
            pnlSearchbox.Visible = false;
            pnlResults.Visible = false;
            pnlDetails.Visible = true;
        }
    
        protected void lnkDetailsBack_Click(object sender, EventArgs e)
        {
            ShowResults();
        }
    
        protected void dsSearchResults_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            lblCount.Text = String.Format("{0} Dentists found", e.AffectedRows);
        }
    
        protected void ShowReCAPTCHA(object sender, EventArgs e)
        {
            ((PlaceHolder)rpAddresses.Items[0].FindControl("cphCaptcha")).Visible = true;
        }
    }
    

    解决方案

    Thanks for the answers people, I did try some of these things.

    1. Every control which you wish to access in aspx.cs should have runat="server"

    they do

    1. Build your solution after adding the above tag

    2. If you wish to access the control defined inside the item template of repeater you can do so only inside repeater events for by putting a loop reading all items of repeater

    they are

    Right click on the page where you are getting the error and click on convert to web application... That will solve your error.

    no such option in my IDE, besides I think it would be the whole project, not a page that I convert.

    Check to see if this is a web application project or a website project. A website project would use the CodeFile attribute of the @Page directive, but a web application project wouldn't. If it's trying to compile as a web application project, you would receive these errors because a web application project expects a designer file in addition to the .aspx and .aspx.cs files. The designer contains all the control definitions which in turn which allows you to reference them properly in codebehind (web application uses CodeBehind and not CodeFile attribute as well).

    apparently then my project is a website, not a web application, as it includes the codefile attribute. also, I don't have designer files, so this makes sense.

    Turns out I am trying to edit a solution developed in VS2008, using VS2013, and a lot has changed since then. While the issue was not resolved here, the fix was to create a new VS2013 solution and import the files, it's all working as intended now, thank you.

    这篇关于名称为“控制”并不在当前上下文中存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆