C# 验证虚拟补丁ascx
这是我的密码C# 验证虚拟补丁ascx,c#,asp.net,ascx,C#,Asp.net,Ascx,这是我的密码 protected void SendButton_Click(object sender, EventArgs e) { UserControl uc = new UserControl(); bool Ok = false; string userControl = ""; string ID = "0"; ID = UCid.Text; if(ID == "1")
protected void SendButton_Click(object sender, EventArgs e)
{
UserControl uc = new UserControl();
bool Ok = false;
string userControl = "";
string ID = "0";
ID = UCid.Text;
if(ID == "1")
{
userControl = Server.MapPath(@"~\UCtest_one.ascx");
Ok = true;
}
else if (ID == "2")
{
userControl = Server.MapPath(@"~\UCtest_two.ascx");
Ok = true;
}
else
{
Response.Write("Eror!!! Enter only 1 or 2");
Ok = false;
}
if (Ok)
{
//here
uc = LoadControl(userControl) as UserControl;
ViewUC.Controls.Add(uc);
}
else
{
Response.Write("Eror!!!");
}
}
System.Web.HttpException
HResult=0x80004005
Message='…/UCtest_one.ascx'
是物理路径,但应为虚拟路径。Source=ASCXruntime StackTrace:at ASCXruntime.Default.SendButton\单击 …\Default.aspx.cs:line 43 这是真的`
protected void SendButton_Click(object sender, EventArgs e)
{
UserControl uc = new UserControl();
bool Ok = false;
string userControl = "";
string ID = "0";
ID = UCid.Text;
if(ID == "1")
{
userControl = MapPath(@"~\UCtest_one.ascx");
Ok = true;
}
else if (ID == "2")
{
userControl = MapPath(@"~\UCtest_two.ascx");
Ok = true;
}
else
{
Response.Write("Eror!!! Enter only 1 or 2");
Ok = false;
}
if (Ok)
{
uc = LoadControl(userControl) as UserControl;
ViewUC.Controls.Add(uc);
}
else
{
Response.Write("Eror!!!");
}
}
您不需要server.mappath,只需给它虚拟路径(~\…)