5
Answers

How is this done?

timothy.farrell

timothy.farrell

20y
1.6k
1
I have an application that the users entered data into. When they submit the data it gets inserted into the db. What I would like to do is have all of the information that the user just entered into the webform displayed below the form with a confirmation message. Can someone point me to a link or a tutorial on how to do this in C#? Thank you all. Sincerely, Tim
Answers (5)
0
timothy.farrell
NA 105 0 20y
I have made some progress and can begin to see the light at the end of the tunnel. I have decided to use a 2 page webform where I declare session data on the first page and pass it along to the second. In addition to this, I am also posting data into a SQL db on the second page. My question is, how do I get the submitted values to show up in my asp:label controls? Here is an example: First Page: Webform Code behind Script: public void AddTool_Click (Object sender, EventArgs e) { //String Data string name = "@name"; //Save Session Data Session.Add("Name", name); //Send Data to second page Server.Transfer("webform3.aspx"); Second Page: Webform:
Tool Record
Name:
Codebehind: private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here //Session Variables string name = (string)(Session["Name"]); SqlConnection sqlConn = new SqlConnection("server=C099450d01;uid=##;pwd=##;database=Tools"); sqlConn.Open(); SqlCommand cmd = new SqlCommand("InsertTool",sqlConn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter SqlParam1 = cmd.Parameters.Add("@Name", SqlDbType.NVarChar,255); SqlParam1.Value = Name.Text; Thank you for your help. BTW, does anyone know if this forum has a better way to input code? Sincerely, Tim
0
timothy.farrell
NA 105 0 20y
Mike, I am sorry I called you Mark. Obviously Mark will not reply to me but I am oping that you do. :) Regards, Tim
0
timothy.farrell
NA 105 0 20y
Mark, Thank you very much for taking the time to put up some code. It is beginning to make some sense to me now. Is there anyway I can send you my form code (via email) and we could work from that? I'm not looking for you to do my work, only to check over my modifications based upon your facts so that I don't screw things up too bad. Sincerely, Tim
0
jcity444
NA 286 0 20y
It's actually fairly easy to do with C# Session["Name"] = TextBox1.Text; However you don't need to store anything in sessions to have it appear at the bottom of the page. Simply have a button handler event that handles the click and places the entered text into a table or something. If you are going to redirect the entered information onto another page, then you will need to save it in a session as shown above, and read it back in on the new page. Sample Code shown below: namespace TestForm { /// /// Summary description for WebForm1. /// public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Table Table1; protected System.Web.UI.WebControls.Label Label1; 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); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { TableRow tr = new TableRow(); TableCell tc = new TableCell(); tc.Text = TextBox1.Text; tr.Cells.Add(tc); Table1.Rows.Add(tr); } } } -Mike G.
0
timothy.farrell
NA 105 0 20y
Ok, through some research I have discovered that this functionality could be accomplished via Sessions. However, I have also discovered that this is not easily done in c#.net. Does anyone have any thoughts on this or a link that may help me in accomplishing this? Thank you. Sincerely, Tim