Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:07:01+00:00 2026-05-30T19:07:01+00:00

Alright I have a question that seems simple but I haven’t been able to

  • 0

Alright I have a question that seems simple but I haven’t been able to figure it out.

Just some quick details: I am using Visual Studio 2010 with ASP.NET, VB, and using SQL Server as my database

I am creating a website using ASP.NET and I have a mailing list database, I have a add to mailing list page that takes in certain fields (Name, e-mail, phone number) that are TextBox and a sumbit button. When the submit button is clicked how to do I take the current values of those text fields and add them to the database.

I have done it using the DetailedView which works at adding to the database but I also want to redirect to a different page after inserting.

So my question basically is how to take the values from the TextBox and insert them into the database, or how to I redirect to a different page after inserting a new row with DetailedView.

Here is my code with for the .aspx file, it has both the TextBox’s and the detailed view

 <p class=whiteMail>
    First Name: <asp:TextBox ID="FirstName" runat="server"></asp:TextBox> <br />
    Last Name: <asp:TextBox ID="LastName" runat="server"></asp:TextBox> <br />
    E-Mail: <asp:TextBox ID="Email" runat="server"></asp:TextBox> <br />
    Phone Number: <asp:TextBox ID="PhoneNumber" runat="server"></asp:TextBox> <br />

    <asp:Button ID="Submit" runat="server" Text="Button" />
    <br />

    <asp:DetailsView ID="DetailsView2" runat="server" Height="50px" Width="125px" 
        DataSourceID="SqlDataSource1" AutoGenerateRows="False" CellPadding="4" 
        DataKeyNames="FirstName,PhoneNum,LastName" DefaultMode="Insert" 
        ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <Fields>
            <asp:BoundField DataField="FirstName" HeaderText="First Name" ReadOnly="True" 
                SortExpression="FirstName" />
            <asp:BoundField DataField="LastName" HeaderText="Last Name" ReadOnly="True" 
                SortExpression="LastName" />
            <asp:BoundField DataField="PhoneNum" HeaderText="Phone Number" ReadOnly="True" 
                SortExpression="PhoneNum" />
            <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
            <asp:CommandField ShowCancelButton="False" ShowInsertButton="True" />
        </Fields>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    </asp:DetailsView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Database1ConnectionString2 %>" 
        DeleteCommand="DELETE FROM [MailList] WHERE [FirstName] = @FirstName AND [PhoneNum] = @PhoneNum AND [LastName] = @LastName" 
        InsertCommand="INSERT INTO [MailList] ([FirstName], [PhoneNum], [Email], [LastName]) VALUES (@FirstName, @PhoneNum, @Email, @LastName)" 
        SelectCommand="SELECT [FirstName], [PhoneNum], [Email], [LastName] FROM [MailList]" 
        UpdateCommand="UPDATE [MailList] SET [Email] = @Email WHERE [FirstName] = @FirstName AND [PhoneNum] = @PhoneNum AND [LastName] = @LastName">
        <DeleteParameters>
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="PhoneNum" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="PhoneNum" Type="String" />
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="Email" Type="String" />
            <asp:Parameter Name="FirstName" Type="String" />
            <asp:Parameter Name="PhoneNum" Type="String" />
            <asp:Parameter Name="LastName" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>

    <br />
</p>

And here is the .vb code

Public Class add
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub


Protected Sub Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Submit.Click
    Dim strURL As String = "message.aspx?firstname=" & FirstName.Text & "&lastname=" & LastName.Text()

    Response.Redirect(strURL)
End Sub

Any help or suggestions would be great

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:07:02+00:00Added an answer on May 30, 2026 at 7:07 pm

    I am not sure if I understood well, but I believe that your approach is not correct. Why you are using the textboxes in the beginning of the code?

    You can achieve nicely what you want by using the full capability of the DetailsView. For example you can do something like this:

    <asp:DetailsView ID="DetailsView2" runat="server" Height="50px" Width="125px" 
        DataSourceID="SqlDataSource1" AutoGenerateRows="False" CellPadding="4" 
        DataKeyNames="FirstName,PhoneNum,LastName" DefaultMode="Insert" 
        ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <Fields>
            <asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" 
                        Text='<%# Bind("FirstName") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" 
                        Text='<%# Bind("FirstName") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" 
                        Text='<%# Bind("FirstName") %>'></asp:TextBox>
            </InsertItemTemplate>
         </asp:TemplateField>
             <asp:TemplateField HeaderText="LastName" SortExpression="LastName">
            <ItemTemplate>
                <asp:Label ID="Label2" runat="server" 
                        Text='<%# Bind("LastName") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" 
                        Text='<%# Bind("LastName") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox2" runat="server" 
                        Text='<%# Bind("LastName") %>'></asp:TextBox>
            </InsertItemTemplate>
         </asp:TemplateField>
             <asp:TemplateField HeaderText="PhoneNum" SortExpression="PhoneNum">
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" 
                        Text='<%# Bind("PhoneNum") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox3" runat="server" 
                        Text='<%# Bind("PhoneNum") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox3" runat="server" 
                        Text='<%# Bind("PhoneNum") %>'></asp:TextBox>
            </InsertItemTemplate>
          </asp:TemplateField>
              <asp:TemplateField HeaderText="Email" SortExpression="Email">
            <ItemTemplate>
                <asp:Label ID="Label4" runat="server" 
                        Text='<%# Bind("Email") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="TextBox4" runat="server" 
                        Text='<%# Bind("Email") %>'></asp:TextBox>
            </EditItemTemplate>
            <InsertItemTemplate>
                <asp:TextBox ID="TextBox4" runat="server" 
                        Text='<%# Bind("Email") %>'></asp:TextBox>
            </InsertItemTemplate>
          </asp:TemplateField>
           <asp:CommandField ShowCancelButton="False" ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    </asp:DetailsView>
    

    And then in you code behind you can use the events of the DetailsView to do the redirect like this:

    Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
        EndEditing()
    End Sub
    
    Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
        EndEditing()
    End Sub
    
    Private Sub EndEditing()
        Response.Redirect("Default.aspx")
    End Sub
    

    I just used a the default.aspx for the redirect, but you can use any other page to redirect.

    I hope that this can help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I have an embarrassingly simple question that hopefully has an embarrassingly simple answer.
Alright simple question I have integriters like 5 188 4634 And they all need
Alright I know this is more than likely a amateur question but I have
Alright, I know questions like this have probably been asked dozens of times, but
Alright. So I asked a question here but I feared that I anwsered it
Alright, I presented this question on the MSDN forums but have yet to receive
Alright, possible a naive question here. I have a service that needs to log
Alright, so this question has definitely been asked before, and I was actually able
Alright, I found out in this question that polling sockets does not scale, so
Hi another silly simple question. I have noticed that in certain typedefs in Apple's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.