index.aspx
-----------------------<HTML>
<HEAD>
<title>index</title>
</HEAD>
<body>
<FORM id="form1" runat="server" action="index2.aspx">
<asp:TextBox id="MyTextBox" runat="server"></asp:TextBox>
<asp:Button id="MyButton" runat="server" Text="OK"></asp:Button>
</FORM>
</body>
</HTML>
index2.aspx
------------------------
<script language="C#" runat="server">
void Page_Load()
{
Response.Write (Request.Form["MyTextBox"]);
}
</script>
解决方案 »
- winform定时发送邮件
- 怎么取 里面的 邮编:200030
- 高分求动态生成gridview的绑定前台数据源id问题,gridview控件没有命名容器
- 帮忙推荐个学习vs2005或者vs2008的书 C#语言
- 用FreeTextBox 出来的问题
- dropdownList选值为空???
- |M| 如何记录对SQL数据库的每一次操作 网站安全方面的 大家说说要怎么来做 讨论
- 未将对象引用设置到对象的实例问题
- 如何后台保留小数位数。
- 传值时是中文的,如何将那个中文改为英文或是乱码,能在地址栏上显示乱码或是英文
- 用 Server.Transfer("View.aspx") 转向后,为什么IE的 URL栏地址确不改变?
- 为什么在我自己机器上建立的aspx网页别人看不见?
{
Response.Redirect("index2.aspx");
}
这个控件只能在runat="server的form里,你可以把这个换成
<FORM id="form1" runat="server" action="index2.aspx">
<input type=text name="MyTextBox">
<input id="MyButton" name="MyButton" type="submit" value="OK" >
</FORM>
如下:
在MyButton_Click()事件里string str=MyTextBox.Text.Trim();
Response.Write ("index2.aspx?con="+str);在 index2.aspx
----------
void Page_Load()
{
Response.Write (Request.Form["con"]);
}
就ok了
<FORM id="form1" action="index2.aspx">
<input type=text name="MyTextBox">
<input id="MyButton" name="MyButton" type="submit" value="OK" >
</FORM>
Response.Write ("index2.aspx?con="+str);在 index2.aspx
----------
void Page_Load()
{
Response.Write (Request.Form["con"]);
}
http://www.test.com/index2.asp?text=xxxxx
此方法适合于不需要使用服务器控件的场合。方法二:<INPUT type="submit" value="提交" name="b1" onclick="document.all['Form1'].action='index2.aspx';">原因:
如果 form 标签加了 runat="server" 属性, action 属性设置就不起作用了,ASP.NET生成代码的时候,会把 action 属性设置为本页,如果要转到其他面的话,只能使用脚本控制了。注意:
如果采用上述这种方法,最好在index2.aspx的Page指令里加入以下语句enableViewState="False" enableViewStateMac="False"
否则会出现页面缓存状态被破坏的提示。
------------------------------------------
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body >
<form name="Form1" method="POST" action="WebForm2.aspx" id="Form1">
<FONT face="宋体">
<input name="TextBox1" type="text" id="TextBox1" />
<input type="submit" name="Button1" value="Button" id="Button1" /></FONT>
</form>
</body>
</HTML>
---------------------------------
WebForm2.aspx.cs aspx 文件没改
---------------------------------
public class WebForm2 : System.Web.UI.Page
{
private string strquery;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write(strquery);
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
if(Request.Form["TextBox1"]!=null && Request.Form["TextBox1"] != String.Empty)
strquery=Request.Form["TextBox1"];
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
<input type=text name="MyTextBox">
<input id="MyButton" name="MyButton" type="submit" value="OK" >
</FORM>
用客户端控见
方法二:如果传的值是可以给别人知道的话就很方便
index.aspx的button_click中
Response.Redirect("index2.aspx?str="+MyTextBox.Text);
index.aspx的load中
Response.Write(Request.QueryString["str"]);
<FORM name="form1" action="index2.aspx">
<input name="MyTextBox" >
<input name="MyButton" Text="OK"> </FORM>第二页,直接接收就可以如果不这样,你也可以用BUTTON的CLICK事件来传
void MyButton_Click(object sender,EventArgs e)
{
Response.Redirect("index2.aspx?text="+MyTextBox.Text.ToString()+"");
}
接受页index2.aspx使用这么一句
protected override object LoadPageStateFromPersistenceMedium(){ return null;}
前台index1.aspx代码
如果使用html控件<INPUT onclick="check();" type="button" value="OK">
如果还是使用server控件,需要在后台MyButton.Attributes["onclick"]=="check();" ;<script>
function check()
{document.form1.action ="index2.aspx";
//document.form1.target ="hide";//可以自己修改
document.form1.submit();
}