Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 添加click-if语句_C#_Asp.net - Fatal编程技术网

C# 添加click-if语句

C# 添加click-if语句,c#,asp.net,C#,Asp.net,是否有更好的方法通过addClick(理想情况下,我根本不想要这个,我希望它自动通过) 如果有人有任何建议,我将不胜感激。我认为以下模型可能对您的代码有好处: public void addClick(object sender, EventArgs e) { object control; string opt = (string) HttpContext.Current.Session["whichMenu"]; switch (opt) {

是否有更好的方法通过
addClick
(理想情况下,我根本不想要这个,我希望它自动通过)


如果有人有任何建议,我将不胜感激。

我认为以下模型可能对您的代码有好处:

public void addClick(object sender, EventArgs e)
{
    object control;
    string opt = (string) HttpContext.Current.Session["whichMenu"];

    switch (opt)
    {
        case "systemDateFormats": control = new WorldViewNet.system.DateFormats();
            break;
        case "programmingLabels": control = new WorldViewNet.programming.Labels();
            break;
        case "programmingPLUSearch": control = new WorldViewNet.programming.PLUSearch();
            break;
        case "programmingServings": control = new WorldViewNet.programming.Servings();
            break;
        case "programmingShops": control = new WorldViewNet.programming.Shops();
            break;
        case "programmingTextsSearch": control = new WorldViewNet.programming.TextsSearch();
            break;
        case "systemTemplates": control = new WorldViewNet.system.Templates();
            break;
        default: new WorldViewNet.system.DefaultType();
    }

    ((dynamic)control).addClick();
}

可能是字符串字典=>操作。
public void addClick(object sender, EventArgs e)
{
    object control;
    string opt = (string) HttpContext.Current.Session["whichMenu"];

    switch (opt)
    {
        case "systemDateFormats": control = new WorldViewNet.system.DateFormats();
            break;
        case "programmingLabels": control = new WorldViewNet.programming.Labels();
            break;
        case "programmingPLUSearch": control = new WorldViewNet.programming.PLUSearch();
            break;
        case "programmingServings": control = new WorldViewNet.programming.Servings();
            break;
        case "programmingShops": control = new WorldViewNet.programming.Shops();
            break;
        case "programmingTextsSearch": control = new WorldViewNet.programming.TextsSearch();
            break;
        case "systemTemplates": control = new WorldViewNet.system.Templates();
            break;
        default: new WorldViewNet.system.DefaultType();
    }

    ((dynamic)control).addClick();
}