Trying to override functionality of UpdateButton in FormView for EditItemTemplate

Hi,

I want a page with a FormView to save the record but to go to some other page (not the current page).

At first I tried setting the PostBackUrl to the new page.  It went to the new page but was not saving the form data.

So then I tried capturing the UpdateButton_Click event.  This is what it looks like:

    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        FormView1.UpdateItem(true);
        LinkButton lb = (LinkButton)FormView1.FindControl("UpdateButton");
        lb.PostBackUrl = "Deal.aspx?BookId=" + Request["BookId"];
       
    }

I put a Breakpoint in this routine and it does hit this but it must be too early (or too late) for the PostbackUrl to be changed.

I don't have to do it like above if someone has a better way of doing it.

Thanks
LVL 1
James CochraneB2B FINTECH WRITER/Technology WriterAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
Does the UpdateButton_Click event fire?  I wonder if Server.Transfer is unreachable code.

Bob
0
 
Bob LearnedCommented:
Would a Server.Transfer("Deal.aspx?BookId=" + Request["BookId"]); work?

Bob
0
 
James CochraneB2B FINTECH WRITER/Technology WriterAuthor Commented:
Place this in the UpdateButton_Click event?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Bob LearnedCommented:
Yes.

Bob
0
 
James CochraneB2B FINTECH WRITER/Technology WriterAuthor Commented:
Hey Bob,

Thanks for the suggestion but it didn't seem to work. Here is the code that I used:

    protected void UpdateButton_Click(object sender, EventArgs e)
    {
        FormView1.UpdateItem(true);
        Server.Transfer("Default.aspx");
    }

I also tried the FormView1.UpdateItem(false) but it stays on the same form.

Thanks
0
 
James CochraneB2B FINTECH WRITER/Technology WriterAuthor Commented:
I was looking at the wrong event.  Your solution works great!

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.