How to create a server control on another ASPX file

笑着哭i 提交于 2020-01-15 10:27:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!