Resolved Redirect after SQL insert

Jmoate

New member
Joined
Aug 18, 2022
Messages
2
Programming Experience
Beginner
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 it does the same thing, skipping the insert, so obviously i need to run the sub later, but dont know what to put in to trigger 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" OnClick="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
 
Top Bottom