Update Database and Redirect to new page

  • Thread starter Thread starter jenileo
  • Start date Start date
J

jenileo

Hello!

I'm fairly new to asp.net and I am struggling with getting my form to
post to the database and transfer the user to a new page. I am using
the FormView control. After the user completes the form, they click the
insert button. The insertbutton has command="insert" which is auto
generated when you use the formcontrol. I tried to add an onclick event
as well that does a server.transfer and it seems the onclick event
overrides the command event. I am redirected to a new page but the
database is not updated. I also tried the onunload event, while it
worked for both redirection and database update, it also put page2 on
page1. So I added an if ispostback to the transfer event and it worked
beautifully! However, I have another button that shows a calendar and
puts the date in textbox and what does that do, it fires a postback, so
I get an error on the page. Hopefully this can be understood. The goal
here is to have the user push a button that will insert data into the
database as well as take the user to a new page. I think the key also
is this should be done using the formview control, from my experience
things work a little differently with in the formview control. Let me
know if I can post more info. Thanks!!
 
Hello Jenileo,

I'm not sure I exactly understand your situation but my guess would be that
you want to handle the FormView.ItemInserted event. It occurs when an Insert
button within a FormView control is clicked, but after the insert operation.
In the event you could redirect the user to the new page.
 
Um, he just gave you the suggestion? Your redirect code goes in the
FormView.ItemInserted event
 
Um, I did not realize that? I thought he was reiterating what I was
saying. Must-talk-slowley, I-am-newbie.
I did do the redirect using the formview control and it did not insert
into the database, it only redirected. Here is a snippit, just a
snippit. Maybe I'm not accessing the control correctly? I can post more
code if needed. Thanks in advance for any help that can be offered.
_____________________________________________________________________________________________________________

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
EnableViewState="false" %>

<script language="VB" runat="server">

Sub doSubmit(ByVal Source As Object, ByVal E As
EventArgs)
If IsPostBack Then

Server.Transfer("newissueconf.aspx")
End If
End Sub

</script>

<asp:Button ID="InsertButton" runat="server"
CommandName="Insert" onclick="dosubmit" Text="Log Issue" Width="82px"
/>


</InsertItemTemplate>

</asp:FormView>

</asp:Content>
 
Hi Jeff,

Sounds like you are frustrated with me and I really apologize. I can't
stress enough how new I am to this and I am turning to this group for
support. I appreciate your lead and I will do some reading up on
FormView.iteminserted and see if I can figure this out, (that should
tell you how new I am.) Meanwhile, maybe someone else in the group can
offer some pointers and possible sample code. I am a visual learner and
if I see it in the code, I may better understand what Jeff is trying to
explain.

Thanks again Jeff for your help,
 
If you are using Visual Studio, create a new page and drop a FormView on it.
Then double click on it to get to the code behind, and locate ItemInserted
from the function dropdowns

Jeff
 
Thanks for the further explanation. After looking up the information
you provided this solution worked beautifully. I can't believe how much
there is to learn! Thanks again, I greatly appreciate it.
 
Back
Top