• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 730
  • Last Modified:

aspx vb.net fill form data disappears when submit

I have a submit form that has data filled out but if there is an error in one of the fields or incorrect data when the submit button is pressed, all the data in the form disappears.  I would like to re-populate the form data after the submit when the code catches an error so the customer does not have to re-type all the data over again.  Thhis is an ASPX form with a standard submit button not a form submit button being used.
0
mphillip85
Asked:
mphillip85
1 Solution
 
phoenixfire425Commented:
It sounds like it is doing a post back or is reloading the page after the error happens..

Your best bet is to prevent the error from happening by adding some kind of verification schema.
0
 
jimbobmcgeeCommented:
Sounds like you may have EnablePostback set to false on your Page, Form or Controls.  Or that the form fields you have used are not actually server-side controls.

Look through your ASPX page's HTML; if the form controls are akin to
<input ... />

Open in new window

try adding a unique id attribute and adding runat="server", or changing them to their ASP.NET equivelents (e.g.
<input type="text" />

Open in new window

becomes
<asp:TextBox />

Open in new window

).

J.
0
 
mphillip85Author Commented:
i am using <input type="text" />  and what can I use on the form to validate before I press the submit?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mphillip85Author Commented:
my dropdownlist's , both of them, do not clear only the input boxes clear after the submit has been clicked.
0
 
mphillip85Author Commented:
how can i just re-populate the input text boxes since I have the data saved in a variable(s).

Thanks
0
 
MlandaTCommented:
Since you are using ASP.NET, you should probably think of using ASP.NET Server Controls as opposed to <input type="text" /> controls. The server controls have the great advantage that they automatically maintain state i.e. they remember data across "postbacks". Using <input type="text" /> reverts back to the Classic ASP style where you would need to use the Request.Form collection to write the user's entries back into the form. A simple example is this:
<%@ Page Language="vb" AutoEventWireup="false" %>

<!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">
<script runat="server" language="vb">
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        If TextBox1.Text.ToUpper <> "TEST" Then

            Label1.Text = "Please enter valid firstname"

        Else
            
            Label1.Text = "Writing to database or something... " & Now
            
        End If

    End Sub
 </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    FirstName:
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
    LastName:
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
    <asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />
    <br />
    <asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>
    </form>
</body>
</html>

Open in new window

Just save that code to an ASPX page, say mytestfile.aspx, put it maybe in your \Inetpub\wwwroot and browse for that in your browser: http://localhost/mytestfile.aspx

You will see that it will remember the values supplied to the form on the client side. note: enter "test" in firstname for a successful validation.

hope that helps.
0
 
MlandaTCommented:
for validation, have a look at these notes: http://www.w3schools.com/aspnet/aspnet_refvalidationcontrols.asp
0
 
mphillip85Author Commented:
needed runar="serer" and using a textbox instead of a inputbpx
0
 
migakjeCommented:
As a comment I will tell this.
I had a user where everything disapeared when he submitted the form. After some investigation I found the reason. He copied some text from an email and by doing that he got some linefeeds and maybe some other special characters along with the text (I tried to paste it into Notepad and there I could see it) and that made the form data disapear "out in the blue" when submitted.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now