Solved

How do I add one textbox at a time after a click of a button?

Posted on 2014-04-12
3
377 Views
Last Modified: 2014-04-12
After the click of btnAdd, I want to add one co-author at a time up to 5 possible. Right now, I click the button and I get 5 textboxes.

Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail


Partial Class Submit


    Inherits System.Web.UI.Page
    Dim objdt As System.Data.DataTable
    Dim objdr As System.Data.DataRow
    Dim ds As New DataSet





    Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim strConnection As String = "Data Source=mssql102.manage.myhosting.com;Initial Catalog=db1150602_group3;Integrated Security=False;User ID=u1150602_drnicholsongroup3;Password=w6p?K9x!,l;Connect Timeout=15;Encrypt=False;Packet Size=4096"
        Dim objconnection As New SqlConnection(strConnection)
        Dim mysqlDataAdapter As New SqlDataAdapter("select * From Faculty", objconnection)




        Dim myDataRow As DataRow
        Dim mydatarowscommandbuilder As New SqlCommandBuilder(mysqlDataAdapter)


        mysqlDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
        mysqlDataAdapter.Fill(ds, "Faculty")
        myDataRow = ds.Tables("Faculty").NewRow()
        myDataRow("Work Title") = txtWorkTitle.Text
        myDataRow("Co-Authors") = txtCoAuthor.Text
        myDataRow("Additional Info") = txtAddInfo.Text
        ds.Tables("Faculty").Rows.Add(myDataRow)

        mysqlDataAdapter.Update(ds, "Faculty")




        txtWorkTitle.Text = ""
        txtCoAuthor.Text = ""
        txtCoAuthor2.Text = ""
        txtCoAuthor3.Text = ""
        txtCoAuthor4.Text = ""
        txtCoAuthor5.Text = ""
        txtAddInfo.Text = ""


        Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("username@rowan.edu", "password")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = True
            Smtp_Server.Host = "smtp.gmail.com"
            e_mail = New MailMessage()
            e_mail.From = New MailAddress("username@rowan.edu")
            e_mail.To.Add("username@rowan.edu")
            e_mail.Subject = "Email Sending"
            e_mail.IsBodyHtml = False
            e_mail.Body = DropDownList1.DataTextField
            e_mail.Body = txtWorkTitle.Text
            e_mail.Body = txtCoAuthor.Text
            e_mail.Body = txtCoAuthor2.Text
            e_mail.Body = txtCoAuthor3.Text
            e_mail.Body = txtCoAuthor4.Text
            e_mail.Body = txtCoAuthor5.Text
            e_mail.Body = txtAddInfo.Text
            Smtp_Server.Send(e_mail)
            MsgBox("Mail Sent")
        Catch error_t As Exception
            MsgBox(error_t.ToString)
        End Try


    End Sub




    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles btnAdd.Click

        If (txtCoAuthor2.Visible = False) Then

            txtCoAuthor2.Visible = True

        End If

        If (txtCoAuthor3.Visible = False) Then



            txtCoAuthor2.Visible = True
            txtCoAuthor3.Visible = True
        End If


        If (txtCoAuthor4.Visible = False) Then



            txtCoAuthor2.Visible = True
            txtCoAuthor3.Visible = True
            txtCoAuthor4.Visible = True

        End If

        If (txtCoAuthor5.Visible = False) Then

            txtCoAuthor2.Visible = True
            txtCoAuthor3.Visible = True
            txtCoAuthor4.Visible = True
            txtCoAuthor5.Visible = True

        End If

    End Sub



End Class

Open in new window

0
Comment
Question by:ryanbecker24
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39996785
You could do ELSE Ifs.

If (txtCoAuthor2.Visible = False)

then your next two lines ALREADY do everything needed, so you can either return right away or guard the next conditionals with elses to keep from doing them, too.
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 39996787
So
If (txtCoAuthor2.Visible = False) Then

            txtCoAuthor2.Visible = True
            return

        End If

Open in new window


and so on
0
 

Author Closing Comment

by:ryanbecker24
ID: 39996790
Thank you
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now