Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an input tag in asp.net page in a form which looks like this
HTML
<form method="post" action="Email sent.aspx">
.The input tag goes like
<input type="text" id="txtName" class="text" name="Name" />
. So basically what I want to do is to store the input value in a session and then use it in the Email sent.aspx page.What should I do to achieve my goal?
Posted

string name = Request.Form["Name"]
Session["name"] = name;

// then to retrieve

string name = string.Empty;
if (Session["name"] != null)
{
    name = (string)Session["Name"];
}


I suggest you go through some books on asp.net as this stuff is all fairly basic. If you don't know how to handle form inputs then you'll struggle with most things.
 
Share this answer
 
Comments
Baiju Nath Upadhyay 12-Jun-15 4:55am    
when i press the submit button the page is posted to Email sent.aspx page but I have written the code in some other page. I copied and pasted the code in email sent.aspx page in page load event. i applied the breakpoint and found out that the name is having no value. i have created the session in page load of the default page. I think this is the error. But then where should I create a session??
[no name] 12-Jun-15 8:09am    
well you dont have to create session, it has been created for you when your application started.

just make sure you are saving something in your session variable before you try to retrieve it
Baiju Nath Upadhyay 16-Jun-15 4:07am    
i have to get that value from textbox which is in the form having post method and action emailsent.aspx page and then use the value in the emailsent page.
Give PostbackUrl property to button and then find control in redirected page.


XML
<asp:Button ID="Button1" runat="server"
       Text="Submit Page to Itself"
           onclick="Button1_Click" /> <asp:Button
           ID="Button2" runat="server"
           Text="Submit Page to Webform2.aspx"
           PostBackUrl="~/WebForm2.aspx" />




protected void Page_Load(object sender, EventArgs e)
{
TextBox textbox2;
Calendar calender2;
textbox2 = (TextBox)PreviousPage.FindControl("TextBox1");
calender2 = (Calendar)PreviousPage.FindControl("Calendar1");
Label1.Text = "Hello" + textbox2.Text + "
" +
" Your date of birth is " + calender2.SelectedDate.ToShortDateString();

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900