简体   繁体   English

asp.net C#错误

[英]Error in asp.net C#

How to pass Editor1 as Parameter: 如何将Editor1传递为参数:

In my aspx.cs i am giving a call to a function which is in .cs file for the same project, as follows: 在我的aspx.cs中,我对同一项目的.cs文件中的函数进行了调用,如下所示:

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDown abs = new DropDown();
    abs.dd(this.DropDownList2, this.DropDownList3);
}

.CS file code .CS文件代码

 public void dd(DropDownList DropDownList2, DropDownList DropDownList3)
    {
         //My code which contains DropDownList2 DropDownList3 and Editor1
   }

The error that i am getting is: 我得到的错误是:

Error   1   The name 'Editor1' does not exist in the current context    

The way i have passed DropDownList2 and DropDownList3 i am not able to pass Editor1(It is an ajax control). 我通过DropDownList2和DropDownList3的方式我无法通过Editor1(这是一个Ajax控件)。 How do i pass it? 我如何通过?

In ASP.NET some time in the past i did experienced such things when i did declared controls in .aspx and for some reason they wasn't accessible in code behind, in such situations i just renamed this bad page, created new page with the same code, it helped. 过去一段时间,我在ASP.NET中确实曾在.aspx中声明控件,但由于某种原因,它们无法在后面的代码中访问,所以我确实遇到过这种情况,在这种情况下,我只是重命名了此不良页面,并使用相同的代码,它有所帮助。 But after, when i am switched to MVC, i found that there is no such situations :) 但是之后,当我切换到MVC时,我发现没有这种情况了:)

Have a look in the file "yourpageneme.aspx.designer.cs" if there is no control name you need, in your case it called "Editor1" is it means it wont be available in code behind, so you need to recreate it once again, some times recreation just only of this control wont help, it is still not appearing in ".aspx.designer.cs" in in that cases you need to recreate the page. 如果没有所需的控件名称,请查看文件“ yourpageneme.aspx.designer.cs”,在您的情况下,它称为“ Editor1”,这意味着它在后面的代码中将不可用,因此您需要重新创建一次再次,有时仅仅对此控件的重新创建将无济于事,在这种情况下,您仍然需要重新创建页面,它仍然不会出现在“ .aspx.designer.cs”中。

If for whatever reason your control isn't being assigned a backing property by the designer, you can get a reference to it in your event handler thus: 如果设计者未出于任何原因为您的控件分配后备属性,则可以在事件处理程序中获取对它的引用,因此:

var editor1 = (AjaxControlToolkit.HTMLEditor.Editor)FindControl("Editor1");

and pass this as an extra parameter to the dd method: 并将其作为附加参数传递给dd方法:

public void dd(
    DropDownList DropDownList2,
    DropDownList DropDownList3,
    AjaxControlToolkit.HTMLEditor.Editor Editor1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM