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 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>
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?
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.
1) don’t use the action here, we will use the button click for that.
2)Change the button ,to this and create an event for button click on Page1.aspx.cs
3) On button click check if any value is selected, If selected take the value and pass it on the second page via QueryString.
On Page2.aspx.cs