从DropDownList的值传递使用POST方法等aspx页面 [英] Pass value from DropDownList to other aspx page using POST method

查看:191
本文介绍了从DropDownList的值传递使用POST方法等aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想asp.net和从一个网页尝试发布数据到其他。这是在PHP中那么容易。
我有两个ASPX网页 Page1.aspx的和Page2.aspx

I trying asp.net and trying posting data from one page to other. It was so easy in PHP . I have two aspx web pages Page1.aspx and Page2.aspx

Page1.aspx的在我选择一个选项,在单击提交按钮下降downlist,此值应被传递到Page2.aspx并由其codebehindfile抓获 Page2.aspx.cs 的Request.Form []。

Page1.aspx has a drop downlist in which i select an option and on clicking submit button , this value should be passed to Page2.aspx and captured by its codebehindfile Page2.aspx.cs by Request.Form[].

Page1.aspx的

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Page1.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
</head>
<body>  

    <form id="form1" runat="server" method="post" action="Page2.aspx">

<asp:DropDownList id="DropDownList1" runat="server" >

<asp:ListItem value="">Select</asp:ListItem>
<asp:ListItem value="1">Hello</asp:ListItem>
<asp:ListItem value="2">World</asp:ListItem>
</asp:DropDownList>



<asp:Button  runat="server"  />  
      </form>  
    </body>
    </html>

如何通过从 Page1.aspx的价值?我在做什么错在格式标记?什么是另一种方法?
我应该在 Page2.aspx 做捕获从下拉列表中选择的价值呢?

How to pass value from Page1.aspx? What am I doing wrong in the form tag? What is the alternative method? What should I do in Page2.aspx to capture the selected value from the drop-down list?

推荐答案

首先有很大的区别.NET的工作从PHP时。
使用此链接为更好的理解。
HTTP://net.tutsplus。 COM /教程/ ASP网/ ASP网换PHP开发人员部分-2 /

First of all there are lot of difference while working on .net from PHP. use this link for better understanding. http://net.tutsplus.com/tutorials/asp-net/asp-net-for-php-developers-part-2/

对于你的问题改变一些东西。

For your question change few things.

  <form id="form1" runat="server">

1)不要在这里使用的动作,我们将使用按钮点击的。

1) don't use the action here, we will use the button click for that.

<asp:button id="btnSubmit" onclick="btnSubmit_OnClick" Text="Click Me" Runat="server"></asp:button>

2)更改按钮,这和创建Page1.aspx.cs的按钮单击事件

2)Change the button ,to this and create an event for button click on Page1.aspx.cs

protected void btnSubmit_OnClick(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Value.Length > 0)
{
                Response.Redirect("Page2.aspx?SelectedValue=" + DropDownList1.SelectedValue);
}
}

3)单击按钮检查是否选择了任何价值,如果选择拿这个值通过查询字符串传递的第二页上。

3) On button click check if any value is selected, If selected take the value and pass it on the second page via QueryString.

在Page2.aspx.cs

On Page2.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {
          string v = Request.QueryString["SelectedValue"];
     }

这篇关于从DropDownList的值传递使用POST方法等aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆