.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Save any name in web form using viewstate

Posted By:satyapriyanayak       Posted Date: October 31, 2013    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

We will know how to save and retrieve any name in web form using view state.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:TextBox runat="server" id="Name" />
        <asp:Button runat="server" id="setname" onclick="setname_Click"
            text="Set name" />
        <asp:Button runat="server" id="Retrivename" text="Retrive Name"
            onclick="Retrive_Click" />
        <br /><br />
        Name retrieved from ViewState: <asp:Label runat="server" id="lblname" />

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub setname_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles setname.Click
        ViewState("UserName") = Name.Text
    End Sub

    Protected Sub Retrive_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Retrivename.Click
        If (ViewState("UserName") <> Nothing) Then
            lblname.Text = ViewState("UserName").ToString()
            lblname.Text = "Notset"
        End If
        Name.Text = ""
    End Sub
End Class


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend