0

I am learning ASP.NET 4 and i am trying to a form which the user enter details into text boxes and drop downs and then presses enter to complete form and the details go into a database in Oracle. What i would like to do is when the enter button is pressed i would like it to clear the form of anything entered and then show a message to say something like 'Thank you for your details'.

The form is working and records all the information to the database so all i need help with is clearing the form after button pressed and then to show message.

I'm not sure what code i need to show you so please ask if you do or anything else if i have not explained myself enough.

Thanks

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="StyleSheet.css" rel="stylesheet" />
<title></title>

</head>
<body>
<form id="form1" runat="server">

<div id="navigationB">
    <ul id="nav">
        <li><a href="Net3.aspx">Home</a></li>
        <li><a href="news.aspx">News</a></li>
        <li><a href="Contact.aspx">Contact</a></li>
        <li><a href="About.aspx">About</a></li>
        <li><a href="Default.aspx">Finance Help</a></li>
    </ul>

</div>


<div id="dform">
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />

    <h3 id="head3"><u>Please Enter Your Details:</u></h3>

    Enter Your Name:
    <asp:TextBox ID="nameB" runat="server"></asp:TextBox>*&nbsp;&nbsp;&nbsp; <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="You Must  Provide Your Name" ControlToValidate="nameB"></asp:RequiredFieldValidator>
    &nbsp;<br />
    Enter Your Age:
    <asp:TextBox ID="ageB" runat="server"></asp:TextBox>*&nbsp;&nbsp;&nbsp; &nbsp;  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ageB"    ErrorMessage="You Must Enter Your Age"></asp:RequiredFieldValidator> &nbsp; <asp:RangeValidator     ID="RangeValidator1" runat="server" ErrorMessage="Age Must be Between 1-99" ControlToValidate="ageB"     MaximumValue="99" MinimumValue="1" SetFocusOnError="True"></asp:RangeValidator>
    &nbsp;
    &nbsp;<br />
    <br />
    Male:
    <asp:CheckBox ID="cbMale" runat="server" groupname="sexB" />
    <br />
    Female:
    <asp:CheckBox ID="cbFemale" runat="server" groupname="sexB"/>

    <br />
    <br />
    <h3 id="header3"><u>Select Hospital Department</u></h3>

    <asp:DropDownList ID="DDList" runat="server" Width="201px">

    </asp:DropDownList>*&nbsp;&nbsp;&nbsp;&nbsp; 

    &nbsp;&nbsp;&nbsp;

    &nbsp;
    <asp:DropDownList ID="DDList2" runat="server" Width="145px">

    </asp:DropDownList>*&nbsp;&nbsp;&nbsp;&nbsp; 
    <br />
    <asp:RequiredFieldValidator runat="server" ErrorMessage="You Must Select One Option"     ControlToValidate="DDList"></asp:RequiredFieldValidator>

     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; <asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ErrorMessage="You Must  Select One Option" ControlToValidate="DDList2"></asp:RequiredFieldValidator>
    <br />
    <br />
    <asp:Button ID="ButtonEnt" runat="server" Text="Enter"/>          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;      <asp:Button id="btnReset"       onclick="btnReset_Click" runat="server" Text="Reset Form"></asp:Button>
    <br />
    <br />
    <asp:Label ID="requiredField" runat="server" Text="(*) Denotes Required Field"></asp:Label>
    &nbsp;&nbsp;&nbsp;
    <br />


</div>
</form>
</body>
</html>

My Function..

Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports System.Data


Public Class sqlFunc

Public Shared Function tableData() As DataSet

    Dim oraConnect As New OracleConnection
    oraConnect.ConnectionString =   ConfigurationManager.ConnectionStrings("smart_dev").ConnectionString

    Dim oraCommand As New OracleCommand

    oraCommand.Connection = oraConnect
    oraCommand.CommandType = Data.CommandType.Text

    Dim lsSQL As String = ""
    lsSQL = "SELECT code, description FROM ref_code WHERE domain = 'SPECIALTY'"

    oraCommand.CommandText = lsSQL

    Dim da As New OracleDataAdapter(oraCommand)
    Dim ds As New DataSet
    da.Fill(ds)

    Return ds
End Function

Public Shared Function tableData2() As DataSet

    Dim oraConnect As New OracleConnection
    oraConnect.ConnectionString = ConfigurationManager.ConnectionStrings("smart_dev").ConnectionString

    Dim oraCommand As New OracleCommand

    oraCommand.Connection = oraConnect
    oraCommand.CommandType = Data.CommandType.Text

    Dim lsSQL As String = ""
    lsSQL = "SELECT code, description FROM ref_code WHERE domain = 'CATEGORY'"

    oraCommand.CommandText = lsSQL


    Dim da As New OracleDataAdapter(oraCommand)
    Dim ds As New DataSet
    da.Fill(ds)


    Return ds
End Function

Public Shared Function dataInsertTable(ByVal sName As String, ByVal iAge As Integer, ByVal sSelect As String, ByVal dList As String, ByVal dList2 As String) As String

    Dim answer As String = "Y"

    Dim conSmart As New OracleConnection
    conSmart.ConnectionString = ConfigurationManager.ConnectionStrings("smart_dev").ConnectionString

    Dim oraCommand As New OracleCommand

    oraCommand.CommandType = Data.CommandType.Text
    oraCommand.Connection = conSmart

    Dim lsSQL2 As String = ""
    lsSQL2 = "INSERT INTO TEST_JC VALUES ('" & sName & "','" & iAge & "','" & sSelect & "','" &   dList & "','" & dList2 & "' , sysdate )"

    oraCommand.CommandText = lsSQL2

    Try
        conSmart.Open()
        oraCommand.ExecuteNonQuery()
        conSmart.Close()
    Catch ex As Exception
        answer = ex.Message
    End Try

    Return answer
End Function
End Class

3 Answers3

0

put these lines like this in your button click event after saving values in database :

nameB.Text = "";
ageB.Text = "";
...
cbMale.Checked = false;
...

and bind your dropdownlists again too and finally show your message

Nima Derakhshanjan
  • 1,380
  • 9
  • 24
  • 37
  • sorry i should of said i am using a function to save the information to a database with SQL, would i put this code in that function or still on the button click event? –  Oct 23 '14 at 08:58
  • well you can use it at end of the function,but please show your code too – Nima Derakhshanjan Oct 23 '14 at 09:25
0

On submit do, call Clear();

  public void Clear()
   {
    txtname.text="";
    txtage.text="";
   }

   Protected void btnsubmit_click()
   {
     Scriptmanager.Registerstartupscript(this, GetType(), "show your alert message","showalert()", true)
     Clear();
    }
Manish Goswami
  • 863
  • 10
  • 27
0
    Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles  btnSubmit.Click 
ScriptManager.RegisterStartupScript(Me, [GetType](), "displayalertmessage", "Showalert();", True)
    txtname.Text = "" 
    txtage.Text = ""  
    dropdownlist.Text = "" 
End Sub

This will Help you.

Manish Goswami
  • 863
  • 10
  • 27