# .NET and More > ASP.NET And ASP.NET Core >  [RESOLVED] ASP.net VB Redirect after form insert to SQL.

## jmoate

I hope someone can help! I am a newbie/code monkey who can get by with a few things but this one has me pulling my hair out how simple I assume it is.  I have a form on an aspx file which when the user fills it in and clicks the insert button, it adds the data to the sql using a stored procedure. This all works fine.

However at the moment it then just refreshes the page to a blank form, what I would like to happen is simply redirect to an external HTTPS site. I tried the PostBackUrl on the button, but then it skips the actual data insertion. I have tried adding a subby on the codebehind VB file, but nothing happens, it just refreshes the form as it its ignoring it. Any help would be much appreciated. There is a master page to handle the css, content tags and footer which I guess has no relevance to assist here, unless I'm wrong.  The two files are as follows (main form simplified to reduce the amount to read):

*Form.aspx*

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="otherfile.aspx.vb" Inherits="otherfile"%>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <title>blah blah</title>
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:FormView ID="FormView1" runat="server" DataKeyNames="datakeyname" 
        DataSourceID="SqlDataSource1" DefaultMode="Insert" style="width:100%">
        <InsertItemTemplate>

                <form action="">

                  <fieldset>
                    <legend>
                      <h3>Account Details</h3>
                    </legend>
                    <div  class="account-details">
                        <div><label>afield</label><asp:TextBox name="afield" ID="afield" runat="server" 
                        Text='<%# Bind("afield") %>'/></div>
                       <div style="justify-content: center;">
                        <asp:RequiredFieldValidator
                        Display="Dynamic" 
                        ID="emvalidator" 
                        runat="server"
                        ControlToValidate="SupervisorEmailTextBox"
                        ErrorMessage="This cannot be left blank"
                        forecolor="Red" >
                        </asp:RequiredFieldValidator>
                        </div>   

                    </div>
                  </fieldset>


                </form>
               <div style="text-align:center;">
                <asp:Button Class="buttoninsert" ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="insert" Text="Create Account" onlick="finished_click" />/></div>
        </InsertItemTemplate>
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ mystring %>" 
        InsertCommand="mystoredprocedure"
        InsertCommandType="StoredProcedure">

        <InsertParameters>

            <asp:Parameter Name="afield" Type="String" />            

        </InsertParameters>

    </asp:SqlDataSource> 

  </asp:Content>



*My code behind file* 


Partial Class otherfile
    Inherits System.Web.UI.Page


Private Sub finished_Click(sender As Object, e As EventArgs)
     Response.Redirect("https://mysite.blah")
  End Sub

End Class

----------


## jmoate

I just saw how dumb I have been! From all the focus I was putting on the VB subby I completely missed I had a typo in the OnClick.  Doh!!!!

----------


## jmoate

Oh no, this isn't resolved! I just found that the VB subby skips the data insertion.  I also have no idea how to untick the resolved status of this.

----------


## jmoate

Resolved my self. 

For those who have the same issue where they need to insert data to SQL on click but then run a command after the data has been posted to the SQL server. There is an OnInsert function that you can add to the button where you can then link to a Sub.

----------

