0

i have a custom event handler in the page, and it is called by the user controls of it.

everything is fine, except there is error display in the code ( red highlighted), but the program can be compiled, and able to run with no apparent error.

but i want to fix (or understand) the reason why the visual studio showed error for that

the error is enter image description here

the code is

-PAGE

Operator_agentcontrol2 agentcontrol = (Operator_agentcontrol2)Page.LoadControl("~/operator/agentcontrol2.ascx");
agentcontrol.displayLevel = (int)Common.WinLose_Level.lvChild4 + 10 + (Panel_agents.Controls.Count * 10);
agentcontrol.AppendProcess += Append_UC_Progress;//Error line

the event in the page-

public void Append_UC_Progress(object sender, EventArgs e)
{
        Common.WinLose_ProgressStage wps = (Common.WinLose_ProgressStage)e;
        progress.AppendProgress(wps);
        SaveProgressVS();
}

-USER CONTROL

public partial class Operator_agentcontrol2 : System.Web.UI.UserControl
{
    public event EventHandler<Common.WinLose_ProgressStage> AppendProcess;
}

Thanks

---Update--- I have tried to follow https://msdn.microsoft.com/en-us/library/db0etb8x(v=vs.85).aspx for the custom event handler.

but then i got this error enter image description here

---Update--- Eventually I found that actually my scenario doesn't require to use something like EventHandler

i have changed the code in user control

public partial class Operator_agentcontrol2 : System.Web.UI.UserControl
{
    public event EventHandler AppendProcess;
}

By doing this the error is gone, and the user control still able to call the Page's function successfully with an object Common.WinLose_ProgressStage.

SKLTFZ
  • 841
  • 2
  • 10
  • 30

1 Answers1

0

As far as I can see, two errors are being reported...

1 - It cannot find a suitable overload for Append_UC_Progess (which takes a Common.WinLose_ProgressStage as an argument)

2 - The assembly containing Common.WinLose_ProgressStage is not referenced.

What I would suggest is happening, is that once it is all compiled the assembly containing Common.WinLose_ProgressStage gets pulled in (perhaps by another referenced assembly), and thus it is noticed that it inherits from EventArgs. It can therefore find a suitable overload of Append_UC_Progess and it all resolves ok.

In order to get rid of the error, I would suggest explicitly referencing the assembly containing Common.WinLose_ProgressStage, so that Visual Studio can see the inheritance tree at design time.

Stephan
  • 591
  • 4
  • 7
  • not really, Common.WinLose_ProgressStage is just a normal class file, there is many other class and variable in that file, the main different of WinLose_ProgressStage from other classes is just it inherited the EventArgs so that it can be put in EventHandler ( Please check the user_control code), thanks – SKLTFZ Dec 20 '16 at 06:37
  • Is it in the same assembly as the page? The error suggests that it is not, and it is in an assembly called `App_Code.xyvqhtbf` that needs to be referenced from the page. – Stephan Dec 20 '16 at 06:43
  • Or perhaps you have fallen into this trap: http://stackoverflow.com/a/1222293/3111401 – Stephan Dec 20 '16 at 06:47
  • i am using VS2015 and i didn't see properties in the drop down list, for the properties window below of the solution explorer, it doesn't contain the related field – SKLTFZ Dec 20 '16 at 07:03