I'm working on my school project in which I need to build up one original web application. But I got an error when I tried to connect two web forms in my project. I have no idea what's wrong about it, and I have looked at many video instruction sources showing how to do it, and still I have the same error. Here is what I have done.
First, I created a web from and named it MainForm
and also I made another one and named TestForm1
. Then, I put a button on TestForm1 aspx file, double-clicked the button to call the cs file, and there I coded
protected void Button1_Click(object sender, EventArgs e)
{
MainForm newWindow = new MainForm();
newWindow.Show();
}
Here, an error comes up and I see a red line under "Show" The error says
MainFor1 does not contain a definition for "Show," and no extension method accepting a first argument of type "MainForm" could be found.
What is wrong about my code? I just simply made two forms and am trying to connect them. Please tell me how I can handle this problem.
Sorry for my bad English, since I'm not a native speaker. And Thank you in advance.
根据我的Understating你想导航到另一个页面,你可以添加一个链接按钮,带你到另一个页面,如下所示:
<asp:Button ID="Button3" runat="server" Text="Button" PostBackUrl="anotherpage.aspx" />
To show a new Page (not a Form!) means that you want the Web Browser to open a new URL. This can be done in many ways, and the way closest to your orignal code is this:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("MainForm.aspx");
}
A Redirect
literally tells the browser: please go to another URL. The browser then makes a new http request with the new URL, and the server then shows that page.
You need to use Server.Transfer()
, method Show()
can't be used in WebForms. Probably You are wrong WinFroms with WebForms.
Server.Transfer("TestForm1.aspx", true);
Here you find introduction to ASP.NET and Web Forms
Summary: This article explains how Web Forms are fundamental to Microsoft ASP.NET, shows how to build a Web form, and discusses the controls essential for building a Web Form. (16 printed pages)
Objectives
- Learn about Web Forms
- Learn the Web controls that are built into Web Forms
- Build a Web Form
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.