欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net 中将表单提交到另一页 Code-Behind(代码和html在不同的页面)

程序员文章站 2024-03-09 16:04:23
the following shows a complete example of the code-behind file associated with the web...
the following shows a complete example of the code-behind file associated with the web forms page sending the information. depending on whether you use visual basic or c#, make sure this sample is called firstpage.aspx.vb or firstpage.aspx.cs, respectively.
[visual basic]
imports system
public class firstpageclass :
inherits system.web.ui.page
protected first as system.web.ui.webcontrols.textbox
protected last as system.web.ui.webcontrols.textbox
protected button1 as system.web.ui.webcontrols.button
public readonly property firstname() as string
get
' first is the name of a textbox control.
return first.text
end get
end property
public readonly property lastname() as string
get
' last is the name of a textbox control.
return last.text
end get
end property
sub buttonclicked(sender as object, e as eventargs)
server.transfer("secondpage.aspx")
end sub
end class
[c#]
using system;
public class firstpageclass : system.web.ui.page
{
protected system.web.ui.webcontrols.textbox first;
protected system.web.ui.webcontrols.textbox last;
protected system.web.ui.webcontrols.button button1;
public string firstname
{
get
{
return first.text;
}
}
public string lastname
{
get
{
return last.text;
}
}
void buttonclicked(object sender, eventargs e)
{
server.transfer("secondpage.aspx");
}
}
the following shows a complete example of how to create a web forms page with a code-behind file to pass the values of two textbox controls to another web forms page. make sure this sample is called firstpage.aspx.
[visual basic]
<%@ page language="vb" inherits="firstpageclass" %>
<html>
<head>
</head>
<body>
<form runat="server">
first name:
<asp:textbox id="first"
runat="server"/>
<br>
last name:
<asp:textbox id="last"
runat="server"/>
<br>
<asp:button
id="button1"
onclick="buttonclicked"
text="go to second page"
runat=server />
</form>
</body>
</html>
[c#]
<%@ page language="c#" inherits="firstpageclass" %>
<html>
<head>
</head>
<body>
<form runat="server">
first name:
<asp:textbox id="first"
runat="server"/>
<br>
last name:
<asp:textbox id="last"
runat="server"/>
<br>
<asp:button
id="button1"
onclick="buttonclicked"
text="go to second page"
runat=server />
</form>
</body>
</html>
to receive server control values from a different web forms page
the following shows a complete example of the code-behind file associated with the web forms page receiving the information. depending on whether you use visual basic or c#, make sure this sample is called secondpage.aspx.vb or secondpage.aspx.cs, respectively.
[visual basic]
imports system
public class secondpageclass
inherits system.web.ui.page
protected displaylabel as system.web.ui.webcontrols.label
public fp as firstpageclass
sub page_load()
if not ispostback then
fp = ctype(context.handler, firstpageclass)
end if
end sub
end class
[c#]
using system;
public class secondpageclass : system.web.ui.page
{
protected system.web.ui.webcontrols.label displaylabel;
public firstpageclass fp;
void page_load()
{
if (!ispostback)
{
fp = (firstpageclass) context.handler;
}
}
}
the following shows a complete example of how to create a web forms page with a code-behind file to receive the values passed from a different web forms page. make sure this sample is called secondpage.aspx
[visual basic]
<%@ page language="vb" inherits="secondpageclass" %>
<%@ reference page="firstpage.aspx" %>
<html>
<head>
</head>
<body>
<form runat="server">
hello <%=fp.firstname%> <%=fp.lastname%>
</form>
</body>
</html>
[c#]
<%@ page language="c#" inherits="secondpageclass" %>
<%@ reference page="firstpage.aspx" %>
<html>
<head>
</head>
<body>
<form runat="server">
hello <%=fp.firstname%> <%=fp.lastname%>
</form>
</body>
</html>