Error in asp.net C#

99封情书 提交于 2020-01-07 04:41:08

问题


How to pass Editor1 as Parameter:

In my aspx.cs i am giving a call to a function which is in .cs file for the same project, as follows:

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

.CS file code

 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). How do i pass it?


回答1:


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:

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



回答2:


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. But after, when i am switched to MVC, i found that there is no such situations :)

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.



来源:https://stackoverflow.com/questions/4613603/error-in-asp-net-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!