Link to home
Start Free TrialLog in
Avatar of James Cochrane
James CochraneFlag for United States of America

asked on

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
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

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

Bob
Avatar of James Cochrane

ASKER

Place this in the UpdateButton_Click event?
Yes.

Bob
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
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was looking at the wrong event.  Your solution works great!

Thanks