Connector/Net Tutorials
1871
1. Select the
Default.aspx
and switch to Design View. Add a text box and three buttons. Change
the text property for the buttons to “Store Session Variable”, “Clear Textbox”, and “Show Session
Variable”. These will be
Button1
,
Button2
and
Button3
respectively. Build your solution to
ensure that no errors have been introduced.
2. Still in the Design View, double-click
Button1
. Now to the
Button1_Click
event handler add
code some the handler resembles the following:
protected void Button1_Click(object sender, EventArgs e)
{
Session["SessionString"] = TextBox1.Text;
}
You have created a new Session variable accessed using the key “SessionString”. This will be set
to the text that was entered into the text box when
Button1
is clicked.
3. In Design View, double-click
Button2
to add its click event handler. This button needs to clear text
from the text box. The code to do this is as follows:
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
}
The code simply assigns an empty string to the
Text
property of the text box.
4. In the Design View double-click
Button3
and modify the click handler as follows:
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.Text = (String)Session["SessionString"];
}
This will retrieve the session string and display it in the text box.
5. Now modify the
Page_Load
method as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox1.Text = "Enter some text";
}
}
This ensures that when the page loads the text box
Text
property is reset.
6. Ensure that the solution is saved and then rebuild the solution.
7. Run the solution without debugging.
8. The form will be displayed. Enter some text into the text box. Now click Store Session Variable. At
this point you have stored the string in a session variable.
9. Now click Clear Text to clear the text box.
10. Now click Show Session Variable to retrieve and display the session variable.
11. Refresh the page to destroy the form and display a new form.
12. Click Show Session Variable the text box will display the stored session variable, demonstrating
that the refreshing the page does not destroy the session variable.
This illustrates that the session state data is not destroyed when a page is reloaded.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...