Help! How do I redirect user after the form data submitted into database?

I know this sounds simple. And I have done numerious redirection using ASP, VB.NET. I am new to C# and I modify someone else code. I tried every single way I know and it still can't recgnize response.direct! BTW, this is asp.net 2.0, the code list below is reside /App_Code fodler. Not the direct code behind. Please help!

using (OleDbCommand command = new OleDbCommand("AddSite;", connection))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new OleDbParameter("@skid", skid));
command.Parameters.Add(new OleDbParameter("@email", email));

connection.Open();
try
{
command.ExecuteNonQuery();
Response.Redirect("Links.aspx", false);

}
catch (Exception ex)
{
throw (ex);
}

}
}

Sue



Answer this question

Help! How do I redirect user after the form data submitted into database?

  • cjarvis

    Thanks Brendan, I got it work out!

  • GerryT

    Because this code is in the App_Code folder it is likely that it is not a page but instead a behind the scenes helper class, because of that, it doesn’t have ready access to Response.Redirect.

    Response is a property of an instantiated page that inherits from the Page class... one fix for this would be to have your helper class in App_Code be aware of the page it is being called from ala: (making sure that you pass a reference in from the caller)

    public void YourFunction(System.Web.UI.Page callingPage)
    {
    using (OleDbCommand command = new OleDbCommand("AddSite;", connection))
    {
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new OleDbParameter("@skid", skid));
    command.Parameters.Add(new OleDbParameter("@email", email));

    connection.Open();
    try
    {
    command.ExecuteNonQuery();
    callingPage.Response.Redirect("Links.aspx", false);

    }
    catch (Exception ex)
    {
    throw (ex);
    }
    }
    }



  • Help! How do I redirect user after the form data submitted into database?