First post for me, hope this is right place rather than c#
I have a form. When it is completed, it redirects the user to a thank you page.
<%@ Page Language="C#" masterpagefile="../../../msrtpage/hra2.master" title="Sign Up Here" %>
<asp:Content id="Content1" runat="Server" contentplaceholderid="hra1">
<script runat="server">
protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
Response.Redirect("thanksfirst.aspx");
}
<asp:FormView id="FormView1" runat="server" CssClass="dform" DataKeyNames="ID" DataSourceID="entrysheet" DefaultMode="Insert" OnItemInserted="FormView1_ItemInserted" >
I left the full form out of this but the button command is "insert".
In my example, these are my listitem values bound to a db column "event"
<asp:listbox id="ListBox5" runat="server" selectedValue='<%# Bind("event") %>' Rows="3">
<asp:listitem Value="Falcon"></asp:listitem>
<asp:listitem Value="Fairlane"></asp:listitem>
<asp:listitem Value="Galaxie"></asp:listitem>
</asp:listbox>
So what I need help with is to define the response.redirect so that the user goes to the correct page based on the selected item. For example, if "Falcon" is selected, it redirects to thanksFalcon.aspx, if Fairlane is selected, redirects to thanksFairlane.aspx, "Galaxie" redirects to thanksGalaxie.aspx.
The closest I've come to solving this, with some help, is
<script runat="server">
protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
Control myControl = FindControl("ListBox5");
string urlpart = ((ListBox) myControl).SelectedItem.Text;
HttpContext.Current.Response.Redirect("thanks" + urlpart + ".aspx");
}
</script>
This renders a page but produces this error when "insert" is pressed:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Most all the other attempts produce an error before the page renders similar to:
CS0103: The name 'ListBox5' does not exist in the current context
I'd sincerely appreciate any help to solvet his problem. My skills with c# are rudimentary.