问题
I am developing a C#/SQL ASP.NET web application in VS 2008. Currently, I am transferring control from one ASPX file to another:
if (uploadFile.PostedFile.ContentLength > 0)
{
inputfile = System.IO.File.ReadAllText(path);
Context.Items["Message"] = inputfile; //Page1
Server.Transfer("DataMatch.aspx"); //Page1
}
However, it fails on this Server.Transfer line after inserting
runat="server"
in the DataMatch.aspx file to the Table element like so:
<table width="50%" id="tMain" runat="server">
But after making this a server control, I rebuilt it and now when I run this app it gives me exception:
Error executing child request for DataMatch.aspx
But I need this table to be a server control so I can make it invisible programmatically if a certain condition occurs. How else can I programmatically make this table invisible?
回答1:
remove the "runat" tag from the table, and instead wrap it in an <asp:Panel>
tag. Apply the visibility attribute to the panel.
来源:https://stackoverflow.com/questions/2647731/how-to-create-a-server-control-on-another-aspx-file