首页 > 网站 > WEB开发 > 正文

跨页面postback时传递JavaScript变量值

2024-04-27 14:01:17
字体:
来源:转载
供稿:网友

需要从HTML页面传值给asp.net页面时,可以使用,很基本,保存下来,以备没学过ASP的新手们不急之需

<html>
<head>
<title>HTML Start Page</title>
</head>
<body>
 <form id="Form1" method="post" action="WebForm1.aspx">
  <input type="text" id="yourTextBox" name="yourTextBox" value="This is the HTML page TextBox value" />
  <input type="hidden" id="yourHiddenElement" name="yourHiddenElement" value="This is the HTML page hidden element value" />
  <input type="submit" value="Go" />
 </form>
</body>
</html>
 
PRivate void Page_Load(object sender, System.EventArgs e)
{
 if ( !this.IsPostBack )
 {
  string textBoxValue = Request["yourTextBox"];
  string hiddenElementValue = Request["yourHiddenElement"];
  this.Response.Write("textBoxValue: " + textBoxValue + "<br>");
  this.Response.Write("hiddenElementValue: " + hiddenElementValue + "<br>");
 }
}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表