ASP.NEt storing data
I have a scenario where i want : To create a data class which will hold data for every element on my web f开发者_如何学编程orm within a property. eg:
public class UserData
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public bool Gender { get; set; }
}
Afterwards, on click of submit button initialize the object of this data class and assign values to respective properties as given below:
UserData userData = new UserData();
userData.FirstName = txtFirstName.Text; // (Always name the controls with prefixes i.e. txt for TextBox, ddl from DropDownList etc.)
userData.MiddleName = txtMiddleName.Text;
userData.FirstName = txtLastName.Text;
userData.Gender = rdbMale.Checked ? "Male" : "Female";
When user will enter a data in a form and click the button, entered data should be displayed on the page. But this should happen every time and on second click of button both the records should display on a page. Means after entering five records, all five should display on page.
I don't know where to store the data. Can anyone help me
You can store the data in a cookie and read the cookie on submit
button click.
But again there are some limitations w.r.t size, user disabling it etc.
Response.Cookies["userName"].Value = txtbox.text;
精彩评论