当前位置: 移动技术网 > IT编程>开发语言>.net > asp.net 中将表单提交到另一页 Code-Behind(代码和html在不同的页面)

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

跨行转账需要多长时间,花千骨全集下载,炒饭西施是谁

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>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网