View Full Version : Submit form in asp.net
andreasberglind
09-13-03, 07:05 AM
I have these two .aspx pages, default.aspx and answer.aspx.
In the first, I have a form with a dropdown list, and a submit button. What I want is to submit the form to answer.aspx by clicking on the button. Could someone give me some help on this?
PLEASE HELP. Itīs probably really simple, but I donīt hace a clue how.
Mister B.
09-13-03, 02:32 PM
<FORM METHOD=POST ACTION=URL>
andreasberglind
09-13-03, 07:32 PM
Then what?
This I have done, but it doesnīt work? what else is needed?
on the other next page put Request.Form("TAG_NAME").
lunatchi
11-14-03, 11:44 AM
Hello,
I am just looking for exactly same information, which is how to pass the value to the next page.
<form method=["post" or "get"] action=URL>
According to my research, couple of pages said that action works only for ASP, and not for ASP.NET. Therefore, even you type this line, browser will ignore the command.
<[@o@]> Here is a code behind code, which ask user to key in their name, and
when the button is pressed, it display the value. However, I want to
retrieve the value in another page. But I couldn't find the example.
All the examples I could find so far is same type of code as below,
using only one page.
Can any body help me with this?
Thanks in advance.
FileName: cb1.aspx
<%@ Page Language="cs" Src="cb1.cs" Inherits="HelloWebFormCs"%>
<HTML>
<HEAD>
<title>C# ASP.NET application with "Code Behind"</title>
</HEAD>
<body>
C# ASP.NET application with "Code Behind"<P />
<form runat="server" ID="Form1">
<asp:textbox id="fld1" runat="server" />
<asp:button runat="server" text="Say Hello" ID="Button1" /><br />
<asp:label runat="server" text="" id="TheLabel" />
</form>
</body>
</HTML>
FileName: cb1.cs
public class HelloWebFormCs : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox fld1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label TheLabel;
override protected void OnInit(System.EventArgs e)
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
base.OnInit(e);
}
private void Button1_Click(object sender, System.EventArgs e)
{
TheLabel.Text = "Hello, " + fld1.Text + "(from an ASP.NET/C# WebForm with code behind)";
}
}
psoutham
11-14-03, 07:59 PM
First off, make friends with MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskpassingvaluesbetweenwebformspages.asp).
You can apporoach this at least two ways...
The First (probably easiest) providing a variable is being passed in the url like http://localhost/nextpage.aspx?fld=myvar:
FileName: nextpage.cs
public class HelloWebFormCs : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label TheLabel;
private void Page_Load(object sender, System.EventArgs e)
{
TheLabel.Text = "Hello, " + Server.HtmlEncode(Request.QueryString["fld1"]) + "(from an ASP.NET/C# WebForm with code behind)";
}
}
The Second is to make use of properties:
formpage.cs
<snip>
private void Button1_Click(object sender, System.EventArgs e)
{
Server.Transfer("datapage.aspx");
}
public string Property
{
get
{
return Label1.Text;
}
}
</snip>
datapage.cs
public class datapage : System.Web.UI.Page
{
public formpage sourcepage;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
sourcepage = (formpage) Context.Handler;
Label1.Text = sourcepage.Property;
}
}
}
It would probably benefit you to download the MSDN Library (http://www.betanews.com/article.php3?sid=1050385180). Hope I've been helpful.
Hello,
I am just looking for exactly same information, which is how to pass the value to the next page.
<form method=["post" or "get"] action=URL>
According to my research, couple of pages said that action works only for ASP, and not for ASP.NET. Therefore, even you type this line, browser will ignore the command.
...
psoutham
11-14-03, 11:07 PM
I made an error in my code above...
Instead of this:
<snip>
public string Property
{
get
{
return Label1.Text;
}
}
</snip>
It should say:
<snip>
public string Property
{
get
{
return TextBox1.Text;
}
}
</snip>
lunatchi
11-18-03, 06:13 AM
Your code gave me some idea of where I have been struggling.
Now, I can pass the value to other page, and retrieve them in the different page.
Thank you very very much!!
lunatchi
11-18-03, 08:33 AM
I think this page gives you some idea about ASP.NET, which describes the differences of ASP and ASP.NET.
First of all, I also used to think in the same way that I can retrieve the data in the same manner as ASP. However, as this page describes that ASP.NET page never accept action even it has been defined as ASP.NET doesn't pass the value to another page. Therefore, always the value obtained in the page have to be processed within the same page... If my understanding is not wrong...
Anyway, I think, this is the page, which answers your questions.
http://www.wimdows.net/articles/article.aspx?aid=8
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.