Dans this question J'ai trouvé ce qui suit, mais il y a deux erreurs que je ne peux pas résoudre. L'erreur est mentionnée avec l'instruction provoquant .Pourquoi est-ce que j'obtiens cette erreur Object Reference and Response not Available?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
//using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string function_name;
function_name = "one";
caller(function_name);
}
static void caller(String function_name)
{
// Get a type from the string
Type type = typeof(_Default);
// Create an instance of that type
Object obj = Activator.CreateInstance(type);
// Retrieve the method you are looking for
MethodInfo methodInfo = type.GetMethod(function_name);
// Invoke the method on the instance we created above
methodInfo.Invoke(obj, null);
}
public void one() //function
{
string a = "\n this is the alphabet a \n";
***//error is***
////Object reference not set to an instance of an object.
////Label1.Text = "one i called";
***//error is***
/////Response is not available in this context.
//// Response.Write(a);
}// function one ends
}
c'est votre solution –
J'ai essayé ce que vous avez dit, mais le "ceci" ne rentre pas dans le cadre de la fonction, seriez-vous plus précis quant à l'endroit où l'ajouter? – user287745
et pourquoi je transmettrais cela à l'appelant, l'appelant a le nom de la méthode. cela n'a rien à voir avec l'obj. Je ne comprends pas .. – user287745