code for the view state

Discussion in 'C#' started by salikkhan, Apr 11, 2011.

  1. #1
    iam working on a web project which involves a inquiry form. can anyone help me in the view state mode of the text box, as i don't want that text box should retain values
     
    salikkhan, Apr 11, 2011 IP
  2. bibinsmk

    bibinsmk Active Member

    Messages:
    205
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    You can set the value to False for EnableViewState property
     
    bibinsmk, Apr 12, 2011 IP
  3. Deu

    Deu Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #3
    on page init

    TextboxID.EnableViewState = false
     
    Deu, Apr 17, 2011 IP
  4. alok.kumar

    alok.kumar Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Maintaining the ViewState is the default setting for ASP.NET Web Forms. If you want to NOT maintain the ViewState, include the directive <%@ Page EnableViewState="false" %> at the top of an .aspx page or add the attribute EnableViewState="false" to any control.
     
    alok.kumar, May 3, 2011 IP
  5. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #5
    Here is the code:
    string strColor;
    if (Page.IsPostBack)
    {
    // Retrieve and display the property value.
    strColor = (string)ViewState["color"];
    Response.Write(strColor);
    }
    else
    // Save the property value.
    ViewState["color"] = "yellow";
     
    unknownpray, Jun 25, 2011 IP
  6. pom4ik

    pom4ik Greenhorn

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    16
    #6
    set the textbox and form to autocomplete="off"

    btw..
    what is the best way to move the viewstate to the bottom of the page?
     
    pom4ik, Aug 30, 2011 IP
  7. cisdeepa

    cisdeepa Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi,
    Try this code

    <script runat="server">
    Sub submit(sender As Object, e As EventArgs)
    lbl1.Text="Hello " & txt1.Text & "!"
    End Sub
    </script>

    <html>
    <body>

    <form runat="server">
    Your name: <asp:TextBox id="txt1" runat="server" />
    <asp:Button OnClick="submit" Text="Submit" runat="server" />
    <p><asp:Label id="lbl1" runat="server" /></p>
    </form>

    </body>
    </html>

    Thanks
     
    cisdeepa, Nov 21, 2011 IP