Hello,
I'm used to work with ColdFusion or PHP. Now I am trying to do the same things with ASP.NET, but I can't figure out how it can / should be done with ASP.NET. I appreciate any help!
I've got form 1: index.aspx
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="AdresApp.index" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Addres applicatie</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content=" </HEAD>
<body MS_POSITIONING="GridLayout">
<form id="index" method="post" runat="server">
<asp:Button id="cmdSubmit" style="Z-INDEX: 101; LEFT: 279px; POSITION: absolute; TOP: 96px" runat="server" Text="Button"></asp:Button>
<asp:Label id="lblName" style="Z-INDEX: 102; LEFT: 139px; POSITION: absolute; TOP: 52px" runat="server">Name:</asp:Label>
<asp:TextBox id="txtName" style="Z-INDEX: 103; LEFT: 183px; POSITION: absolute; TOP: 50px" runat="server"></asp:TextBox>
</form>
</body>
</HTML>
index.aspx.cs
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.TextBox txtName;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
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.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void cmdSubmit_Click(object sender, System.EventArgs e)
{
ViewState["cName"] = txtName.Text;
Server.Transfer("WebForm1.aspx"
}
}
WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="AdresApp.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content=" </HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblPostedName" style="Z-INDEX: 104; LEFT: 174px; POSITION: absolute; TOP: 94px" runat="server"></asp:Label>
</form>
</body>
</HTML>
WebForm1.aspx.cs
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblPostedName;
private void Page_Load(object sender, System.EventArgs e)
{
lblPostedName.Text = (String) ViewState["cName"];
}
}
I start index.aspx I type in my name Charl click the button cmdSubmit. Then the page WebForm1.aspx should be loaded with my name putted into the label lblPostedName.Text.
There are two things I don't know how to realize it:
1. How to change the action property from the html form to another page?
2. I've seen in another post from someone else that I should use Server.Transfer("WebForm1.aspx", but my form variable isn't posted to the next page? How to do this?
Thanks,
Charl
I'm used to work with ColdFusion or PHP. Now I am trying to do the same things with ASP.NET, but I can't figure out how it can / should be done with ASP.NET. I appreciate any help!
I've got form 1: index.aspx
<%@ Page language="c#" Codebehind="index.aspx.cs" AutoEventWireup="false" Inherits="AdresApp.index" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Addres applicatie</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content=" </HEAD>
<body MS_POSITIONING="GridLayout">
<form id="index" method="post" runat="server">
<asp:Button id="cmdSubmit" style="Z-INDEX: 101; LEFT: 279px; POSITION: absolute; TOP: 96px" runat="server" Text="Button"></asp:Button>
<asp:Label id="lblName" style="Z-INDEX: 102; LEFT: 139px; POSITION: absolute; TOP: 52px" runat="server">Name:</asp:Label>
<asp:TextBox id="txtName" style="Z-INDEX: 103; LEFT: 183px; POSITION: absolute; TOP: 50px" runat="server"></asp:TextBox>
</form>
</body>
</HTML>
index.aspx.cs
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button cmdSubmit;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.TextBox txtName;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
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.cmdSubmit.Click += new System.EventHandler(this.cmdSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void cmdSubmit_Click(object sender, System.EventArgs e)
{
ViewState["cName"] = txtName.Text;
Server.Transfer("WebForm1.aspx"
}
}
WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="AdresApp.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content=" </HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblPostedName" style="Z-INDEX: 104; LEFT: 174px; POSITION: absolute; TOP: 94px" runat="server"></asp:Label>
</form>
</body>
</HTML>
WebForm1.aspx.cs
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblPostedName;
private void Page_Load(object sender, System.EventArgs e)
{
lblPostedName.Text = (String) ViewState["cName"];
}
}
I start index.aspx I type in my name Charl click the button cmdSubmit. Then the page WebForm1.aspx should be loaded with my name putted into the label lblPostedName.Text.
There are two things I don't know how to realize it:
1. How to change the action property from the html form to another page?
2. I've seen in another post from someone else that I should use Server.Transfer("WebForm1.aspx", but my form variable isn't posted to the next page? How to do this?
Thanks,
Charl