"Add" and "Add Another" LinkButtons with a PostBackURL and a Redirect

I have a page that allows a user to add a record.  It is a FormView and it has 3 LinkButtons at the bottom.  I would like the "Add" LinkButton to add the record and redirect to a list of records page.  I would like the "Add Another" LinkButton to add the record and stay on the same insert a record page so the user can add another record.  I would like the "Cancel" LinkButton to send the user back to the list of records page.

I have the "Cancel" working using a PostBackURL.

I have the "Add Another" working because it automatically posts back to the same page and is ready to insert again.

I am stuck on the "Add" and redirect.  I know how to use "Response.Redirect" to handle this in the ItemInserted event of the FormView but I cannot do that in this case because the "Add Another" would also cause the redirect.  

I expect it is possible to do this but I definitely have a conceptual problem with the issue because I cannot even think of anything else to try.

Any help would be greatly appreciated.

0
ChibiNopo
9/16/2008 12:35:56 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
775 Views

Similar Articles

[PageSpeed] 26

You'll probably have to add a "klunky" flag something like this:

 

    bool AddingAnother;  // true when Add Another button is clicked

    protected void ButtonAddAnother_Click(object sender, EventArgs e)
    {
        AddingAnother = true;
    }

    protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        if (AddingAnother == true)
        {
            // don't forget to reset the flag
            AddingAnother = false;
            return;
        }

        // we are doing an Add

        Response.Redirect("...");
    }
 
Steve Wellens

My blog
0
SGWellens
9/16/2008 1:06:42 AM

Thanks for the reply Steve.  I'm still not getting it. I see the concept but don't seem to be able to get it working. 

I've added code similar to your example in the codebehind.  I added an OnClick to the LinkButton and an OnItemInserted to the FormView.  The record is being added, but I am still returned to the Insert Template of the FormView.  I also thought maybe the Response.Redirect should be inside the "if" statement because it should only occur when that particular button is clicked.  It didn't work inside or out.

I've tried searching "bool" and "flag" for examples because I've never used anything like this before, but I cannot find an example using "bool" that seem relevant to my situation. 

If you could point me toward a tutorial/example, or maybe give me better search terms, I'll keep working on it.

0
ChibiNopo
9/16/2008 3:16:53 AM
Reply:

Similar Artilces:

"Add Web Reference" -vs- "Add Service Reference"
I've noticed that in VS 2008 I can add a reference to a web service through "Add Service Reference..." or "Add Web Reference".  It appears that either of these approaches works but there are some differences in the naming of the client-side proxy that's generated.. Does "Add Service Reference" take advantage of the 3.5 framework?  Does this approach gain any efficiencies if I'm still adding the reference for an asmx web service rather than a WCF service?  Or does "Add Service Reference" for an asmx web service just pr...

[Suggestion] Add a "Restart " button in "Add-ons" form
Name: Claudio Email: togixatliberodotit Product: Firefox Summary: [Suggestion] Add a "Restart " button in "Add-ons" form Comments: Hi, my name is Claudio and I’m here because I’ve noticed one thing during all this time that I use Firefox (nowadays it’s about two years): when a new Add-on is installed and activate, or a new Theme is selected, a string appears and suggest to restart the browser in order to use it. But sometimes there are many tabs opened and we have to delay the reload and see the effects of the changes. So what I think that could be u...

Precedence of "where" ("of", "is", "will")?
Nobody on #perl6 today could answer this one. Is: Str | Int where { $_ } the same as: (Str | Int) where { $_ } or: Str | (Int where { $_ }) ? Followup questions, Mr. President: What kind of operators are "where", "of", "is", and "will"? Is there a reason that S03 doesn't list them? What are their precedence(s)? -- Chip Salzenberg - a.k.a. - <chip@pobox.com> Open Source is not an excuse to write fun code then leave the actual work to others. Chip Salzenberg writes: &...

.ALLCOL("%COLUMN%", " ", ", ", ", ")
Do you know anyway for me to exclude a subset of columns returned by this function. We have two columns (rec_user and rec_datetime) which are in all of our tables, but when generating triggers I want automatically generate a script which does not include those two columns but does include all other columns in that table. Bruce I should add that I am using PD 9.0.0.580. Bruce "Bruce Lamb" <lamb.bruce@mayo.edu> wrote in message news:6HgI315nCHA.155@forums.sybase.com... > Do you know anyway for me to exclude a subset of columns returned by this > function. ...

Are there different between ViewState.Add("key","Word"); and ViewState["key"] = "Word";
I think the 1 and 2 are complete same, is it correct? 1. ViewState.Add("key","Word"); 2. ViewState["key"] = "Word";SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip filesSuperCool Random Number Generator You are correct, option 2 is short hand for option 1.Philip Beadle (MVP, MCAD, MCT DotNetNuke Core Team)...

quotes, quotes, quotes...
I am getting this error and I know what is causing it, but I have no idea how to fix it, any help would be great. The script steps through the /var/log/messages file on a linux server and puts The entries into a mysql database. However when it gets to the 'hlt' line in the messages file it just barfs. The single quotes are freaking it out. I know about quotes but not how to use in this situation. Thanks, Paul Error: May 27 17:53:00 localhost kernel: Checking 'hlt' instruction... OK. <----- doesn't like this in the messages file DBD::mysql::st exec...

No "Available layouts" to "Add>>" to "Active layouts"
I have US English, Russian and Ukrainian languages in Country/Region & Language. The list of "Available layouts" is empty, any suggestions what to do? Before I removed few packages using YAST, so probably I miss some package? -- magner58 ------------------------------------------------------------------------ > The list of "Available layouts" is empty, any suggestions what to do? i am confused....where are you seeing this "Available layouts"? is that in YaST System > Languages, or ??? -- DenverD (Linux Counter 282315)...

Replacing "\\" with "\"
Hi all I'm getting this value from a CheckBoxList control - a location of file, i have to remove "\\" and replace it with "\" and pass it to Query, how to do it, i tried with Replace, but coud'nt suceed. "\\\\Blaze10xp\\BLZ_SFS_07\\Sample Excel Files\\Excel Files\\report2.xls" thank's in advance - Prakash.C you tried Replace like this? string newstring = oldstring.Replace(@"\\",@"\");Plese, do not forget to click "Mark as Answer" on the post that helped you. Thanx!My blog: Scenes From A Developer Memory yes i tr...

"Using" or "With"
Hi all Please can someone enlighten to me as regards the difference with the "Using" and "With" statement when accessing data - which is better, what are the limitations and/or any pointers. Many thanks. Regards DaveDavid WinchesterPlease mark as answer if this is the solution.  using gives you the ability to use the connection and it closes the connection directlly after you finish using it. and there is no need to try- cach - finaly. there is no limitation on using USING keywordMuhanad YOUNISMCSD.NETMy Blog || My Photos || LinkedIn I have a dataobject the re...

double quote
hello there...  i tried everything of think but not working the way i wanted to be... not sure what i'm missing...i'm generating a <span> in code behind and then using in javascript.... here is what i'm doing code behind: int i=0string _keywordID = "keyword";string _name = row["visit_info_nm"].ToString().Trim(); String _getElementByID = String.Format("<span id='{0}' OnClick = \"document.getElementById('{1}').value='{2}';\">{3}</span><br>", i, _keywordID, _name, _name); here is what it generate : <span id='1' OnClick = \"document.getElementById('keyword')...

"To" and "From" missing
When I print emails, the words "To" and "From" are blank, even though the "To" name and "From name (addresser, addressee) do show up. This is not a problem for other users on my system. Suggestions In mailbox right click, view. On the message window, right click and choose print options. Make sure print header is checked. -- Barry Merchant NSC Volunteer SysOp *** no email unless requested please!! *** > In mailbox right click, view. On the message window, right click and > choose print options. Make sure prin...

replace the "." with a ","
Oi.... I need to build a small programm in ASP.NET and chose to use C# for it.Now i got everything working but there's one little problem.the first textbox is a double. I need to make it so that when someone enters a "." then it gets replaced by a ","any ideas?Ghan  string blah = "4.2.2.2";blah = blah.Replace(".", ",");Ryan Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question...

Using "+" or "||"
Using SQLAnywhere 5.5.04, I've gotten into the habit of using "||" in ISQL to indicate a string concatenation. I needed to paste my SQL statement into the PowerBuilder script painter for some embedded SQL, and PB didn't like the "||" very much at all. I changed it to "+" and it seems to be ok. Do these two operators indicate ~exactly~ the same thing? moin, afaik these two's are not the same! if you're using "||" and any term is NULL then in the resultstring the term will be ignored if you use "+" then the resu...

how to distinguish between "modify" and "add" operation
Hi all, in realizing an SPML driver i notice that driver, by default, transform "modify" event in "add" event. So I can't distinguish between two events. I had to send a request to a WebServer for a service A in case of "modify" event and send a request to the same WS for service B in case of "add" event. Because of this default transformation, driver send always request for service B. Any suggestion will be welcome. thanks -- FedeNovellIM ------------------------------------------------------------------------ Try adding a ...

Web resources about - "Add" and "Add Another" LinkButtons with a PostBackURL and a Redirect - asp.net.web-forms

Resources last updated: 1/2/2016 4:46:03 PM