|
-
Jun 12th, 2005, 01:19 PM
#1
Thread Starter
Member
Form wont Clear after Submit
After the information is put into the SQL server the information in the form doesnt not clear out it just stays there then I have to delete them one by one which is really annoying. Pls can someone show me what Iam doing wrong.
Thanks
Code...
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Dim conn As SqlConnection
Dim param As SqlParameter
Dim cmdcommand as sqlcommand
Sub Page_Load(Src As Object, e As EventArgs)
'Enter your User ID & Password appropriately
conn = New SqlConnection("Data Source=xxx;User ID=xxxx;password=xxxx;Initial Catalog = xxxxx")
conn.open()
End Sub
Sub btnSave_Click(sender As Object, e As EventArgs)
'Stored Procedure name
cmdcommand = new sqlcommand("Register",conn)
cmdcommand.commandtype = commandtype.storedprocedure
param = cmdcommand.parameters.add("ReturnValue",sqldbtype.int)
param.direction = parameterdirection.returnvalue
cmdcommand.parameters.add("@cartname",txtcartname.text)
cmdcommand.parameters.add("@cartphone",txtcartphone.text)
cmdcommand.parameters.add("@cartemail",txtcartemail.text)
cmdcommand.parameters.add("@connection",txtconnection.text)
cmdcommand.parameters.add("@address",txtaddress.text)
cmdcommand.parameters.add("@city",txtcity.text)
cmdcommand.parameters.add("@state",txtstate.text)
cmdcommand.parameters.add("@zipcode",txtzipcode.text)
cmdcommand.parameters.add("@country",txtcountry.text)
cmdcommand.executenonquery()
if cmdcommand.parameters("ReturnValue").value = 0 then
lblStatus.text = "Registered Successfully"
else
lblStatus.text = "Error!, Please try again"
end if
conn.close()
End Sub
</script>
</head>
<title>Add Cart</title>
<style type="text/css">
<!--
.style4 {
font-size: 18px;
font-family: "Times New Roman", Times, serif;
color: #FFFFFF;
}
-->
</style>
<body>
<table width="100%" border="0" cellPadding="0" cellSpacing="0" bgcolor="#336699">
<tr>
<td height="16" class="subHeading style8 style2 style4 style4">Add Cart</td>
<td class="subHeading" width="19%" height="16"> </td>
<td width="25%" height="16" class="subHeading style4"><span class="subHeading "><span class="style3 ">Date:</span></span><%=DateTime.Now.ToString()%> </td>
</tr>
</table>
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<td width="12%"><asp:HyperLink ID="RoleManager" runat="server" NavigateUrl="RoleManager.aspx" Visible="False">Role Manager</asp:HyperLink></td>
<td width="88%" align="right"><asp:HyperLink ID="Account" runat="server" NavigateUrl="Register.aspx">Account</asp:HyperLink>
<asp:HyperLink ID="SignOut" runat="server" NavigateUrl="Login.aspx">Sign Out</asp:HyperLink></td>
</tr>
<tr>
<td colspan="2"><table class="searchLabel" cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td width="59%" colspan="2"><form runat="server">
<table width="100%" border="0" bordercolor="#336699">
<tr>
<td width="23%"><strong>Cart Name</strong></td>
<td width="77%"><asp:TextBox id="txtcartname" runat="server" Width="200px" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td height="22"><strong>Cart Phone</strong></td>
<td><asp:TextBox id="txtcartphone" runat="server" Width="150px" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><strong>Cart Email</strong></td>
<td><asp:TextBox id="txtcartemail" runat="server" Width="200px" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><strong>Connection Status </strong></td>
<td><asp:TextBox id="txtconnection" runat="server" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><strong>Address</strong></td>
<td><asp:TextBox id="txtAddress" runat="server" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><strong>City</strong></td>
<td><asp:TextBox id="txtcity" runat="server" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><strong>State</strong></td>
<td><asp:TextBox id="txtstate" runat="server" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><strong>ZipCode</strong></td>
<td><asp:TextBox id="txtzipcode" runat="server" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><strong>Country</strong></td>
<td><asp:TextBox id="txtcountry" runat="server" CssClass="insidetext"></asp:TextBox></td>
</tr>
<tr>
<td><span class="fieldcaptions">
<asp:Button id="btnSave" onclick="btnSave_Click" runat="server" Text="Save"></asp:Button>
</span></td>
<td><span class="fieldcaptions"> </span>
<asp:Label id="lblStatus" runat="server" ForeColor="#FF8000" Font-Bold="True" Font-Names="Garamond"></asp:Label></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
</body>
</html>
-
Jun 12th, 2005, 07:55 PM
#2
Re: Form wont Clear after Submit
You are not doing anything wrong. Since by default viewstate is set to Enabled for all controls, when you post back all input are restored/kept by asp.net. You can either set the EnableViewstate to false for all the input fields or just simply write a function which clears out all the input value. I will suggest 2nd options. As you need the viewstate incase user has entered wrong input and you dont want the form to be cleared..
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jun 12th, 2005, 10:06 PM
#3
Thread Starter
Member
Re: Form wont Clear after Submit
Can anyone give me any example of the code for this??
-
Jun 13th, 2005, 09:32 AM
#4
Re: Form wont Clear after Submit
Here is an example i put together. If you are using HtmlControls then make sure you set them as Server Controls.
VB Code:
'Usage
''''''''''''''''''''''
Dim ctl As Control
Me.ListBox2.Items.Clear()
For Each ctl In Me.Controls
ClearControls(ctl)
Next
'''''''''''''''''
Private Sub ClearControls(ByVal ctl As Control)
Dim ct As Control
For Each ct In ctl.Controls
If ct.GetType() Is GetType(TextBox) Then
CType(ct, TextBox).Text = ""
ElseIf ct.GetType Is GetType(RadioButton) Then
CType(ct, RadioButton).Checked = False
ElseIf ct.GetType Is GetType(CheckBox) Then
CType(ct, CheckBox).Checked = False
ElseIf ct.GetType Is GetType(ListBox) Then
Dim lb As ListBox
lb = CType(ct, ListBox)
If lb.Items.Count > 0 Then
lb.SelectedIndex = -1
End If
ElseIf ct.GetType Is GetType(DropDownList) Then
Dim lb As DropDownList
lb = CType(ct, DropDownList)
If lb.Items.Count > 0 Then
lb.SelectedIndex = -1
End If
ElseIf ct.GetType() Is GetType(HtmlInputText) Then
CType(ct, HtmlInputText).Value = ""
ElseIf ct.GetType Is GetType(HtmlTextArea) Then
CType(ct, HtmlTextArea).Value = ""
ElseIf ct.GetType() Is GetType(HtmlInputRadioButton) Then
CType(ct, HtmlInputRadioButton).Checked = False
ElseIf ct.GetType() Is GetType(HtmlInputCheckBox) Then
CType(ct, HtmlInputCheckBox).Checked = False
ElseIf ct.GetType() Is GetType(HtmlSelect) Then
Dim sel As HtmlSelect
sel = CType(ct, HtmlSelect)
If sel.Items.Count > 0 Then
sel.SelectedIndex = -1
End If
End If
If ct.Controls.Count > 0 Then
ClearControls(ct)
End If
Next
End Sub
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Jun 14th, 2005, 04:06 PM
#5
Hyperactive Member
Re: Form wont Clear after Submit
I'm a noob, but could you do something like --
Code:
if cmdcommand.parameters("ReturnValue").value = 0 then
Response.redirect("thispage.aspx?Success=true")
else
lblStatus.text = "Error!, Please try again"
end if
Then in the page load request the query string and set
the success message in lblStatus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|