Double "action" in form's View in ASP.NET MVC

Discussion in 'ASP .Net' started by Luigi, Jun 10, 2009.

  1. Luigi

    Luigi Guest

    Hi all,
    in an ASP.NET MVC application, I need to have 2 possible "action" for my
    form's view

    <form id="myForm" action="...">
    .....
    </form>


    depends on which button is pushed by the user.
    With first button the action has to reload the same view, and with the other
    has to pass to the following view.

    How can I accomplish this?

    Thanks a lot.

    Luis
     
    Luigi, Jun 10, 2009
    #1
    1. Advertising

  2. Luigi

    Luigi Guest

    "Mark Rae [MVP]" wrote:
    > Use two <asp:Button /> webcontrols with the same OnCommand method, but give
    > them different CommandArgument properties:
    > http://www.google.co.uk/search?sour...3GB323&q=asp:Button OnCommand CommandArgument
    >
    > Then branch accordingly:
    >
    > <asp:Button ID="MyButton1" runat="server" Text="Button1"
    > OnCommand="MyButton_Command" CommandArgument="1" />
    > <asp:Button ID="MyButton2" runat="server" Text="Button2"
    > OnCommand="MyButton_Command" CommandArgument="2" />
    >
    > protected void lnkEvent_Command(object sender, CommandEventArgs e)
    > {
    > if (e.CommandArgument.ToString() == "1") // MyButton1 was pushed
    > {
    >
    > }
    > else
    > {
    >
    > }
    > }
    >


    What is "lnkEvent_Command" Mark?
    Has to be the name of the onCommand parameter?

    Luis
     
    Luigi, Jun 10, 2009
    #2
    1. Advertising

  3. Luigi

    Luigi Guest

    Another problem, and how can I "set" the Action value of the form in the IF
    clause?

    L
     
    Luigi, Jun 10, 2009
    #3
  4. Luigi

    Luigi Guest

    Hi Mark, is it possible to use only HTML controls, like

    <input type="button" value="Continue"

    or

    <input type="submit" value="Continua"

    instead of Web Controls?

    Luis
     
    Luigi, Jun 10, 2009
    #4
  5. Luigi

    Luigi Guest

    Infact I'm using .ascx view, with no code-behind.

    L
     
    Luigi, Jun 10, 2009
    #5
  6. Luigi

    Luigi Guest

    In my .ascx ASP.NET MVC View I have a form:

    <form id="myForm" name="myForm" action="" method="post">

    ....some textbox controls


    <input type="submit" id="add" name="add" value="Add Data" />

    <input type="submit" id="submitButton" name="submitButton" value="Continue" />


    </form>


    My problem is to have 2 different action - so to post to 2 different views -
    second which button is clicked, and be able to get the controls values.


    L
     
    Luigi, Jun 10, 2009
    #6
  7. Luigi

    Luigi Guest

    Ok Mark, you're right.
    But in the

    if (e.CommandArgument.ToString() == "1")
    {
    // Adding
    }
    else
    {
    // Continue
    }

    how can I pass the values from the first page and the second page (in the
    Else)?

    Luis
     
    Luigi, Jun 10, 2009
    #7
  8. Luigi

    Luigi Guest

    I hate ASP.NET MVC.....you can not make the normal things that happen in
    ASP.NET Web Forms.

    L
     
    Luigi, Jun 12, 2009
    #8
  9. "Luigi" <> wrote in message
    news:...

    > I hate ASP.NET MVC.....you can not make the normal things that happen in
    > ASP.NET Web Forms.


    Why are you using it if you hate it so much? Is someone holding a gun to
    your head?
     
    David Jackson, Jun 12, 2009
    #9
  10. Luigi

    Luigi Guest

    "Mark Rae [MVP]" wrote:
    > So don't use it...


    Because I *must* use .ascx pages (the PM order them), with no code-behind,
    so is difficult to realize this.

    L
     
    Luigi, Jun 12, 2009
    #10
  11. "Luigi" <> wrote in message
    news:...

    >> So don't use it...

    >
    > Because I *must* use .ascx pages (the PM order them), with no
    > code-behind,


    That is one of the stupidest things I've heard in a long time!

    How can you take someone like that seriously?

    Time to look for another job?
     
    David Jackson, Jun 12, 2009
    #11
  12. Luigi

    Luigi Guest

    "David Jackson" wrote:
    > That is one of the stupidest things I've heard in a long time!
    >
    > How can you take someone like that seriously?
    >
    > Time to look for another job?


    The entire application - ASP.NET MVC type - has many .ascx pages, with no
    code-behind, and *only* HTML controls (like <input type=etc....), and I have
    to accomplish this issue following this structure.
    Poor me....

    Luis
     
    Luigi, Jun 12, 2009
    #12
  13. re:
    !>> That is one of the stupidest things I've heard in a long time!
    !>> How can you take someone like that seriously?

    Not at all.

    You can do anything, in inline code, that you can do in code-behind.
    A good programmer needs to be able to program both inline and in code-behind.

    re:
    !> I have to accomplish this issue following this structure.

    There's nothing stopping you.
    You can do everything you need to do using inline code.

    re:
    !> Poor me....

    Only if you let uninformed opinions, like David's, influence your decision.

    Go ahead and program the ascx pages with inline code.
    You can do that in a very productive manner.




    Juan T. Llibre, asp.net MVP
    ¿ Estas probando VS 2010 y ASP.NET 4.0 ?
    Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
    http://asp.net.do/foros/forums/
    =====================================================
    "Luigi" <> wrote in message news:...
    > "David Jackson" wrote:
    >> That is one of the stupidest things I've heard in a long time!
    >>
    >> How can you take someone like that seriously?
    >>
    >> Time to look for another job?

    >
    > The entire application - ASP.NET MVC type - has many .ascx pages, with no
    > code-behind, and *only* HTML controls (like <input type=etc....), and I have
    > to accomplish this issue following this structure.
    > Poor me....
    >
    > Luis
     
    Juan T. Llibre, Jun 12, 2009
    #13
  14. "Luigi" <> wrote in message
    news:...

    >> That is one of the stupidest things I've heard in a long time!
    >>
    >> How can you take someone like that seriously?
    >>
    >> Time to look for another job?

    >
    > The entire application - ASP.NET MVC type - has many .ascx pages, with no
    > code-behind, and *only* HTML controls (like <input type=etc....)


    An ASP.NET app which is not permitted to use webcontrols is plain
    ridiculous!

    Why are you even bothering to use ASP.NET in the first place? Why not just
    use ASP Classic?
     
    David Jackson, Jun 12, 2009
    #14
  15. re:
    !> An ASP.NET app which is not permitted to use webcontrols is plain ridiculous!

    ASP.NET, using MVC, can use web controls.

    You need to understand what MVC is...and why its web controls are programmed differently.

    ASP.NET MVC has the HtmlHelper object which is a property available on every WebControl.
    You can call its extension methods to create the intended html string.

    The result is a string rendered to the view.

    Educate yourself about MVC web controls at :
    http://www.codeproject.com/KB/applications/catharsis_part12.aspx

    There's a complete MVC project, with sample MVC code, available at CodePlex :
    http://www.codeplex.com/Catharsis/

    Feel free to read the other 12 articles of that series on MVC's Web Access layer.

    Notice this in the description :
    "powerful WebControls for large reuse and quick development"

    re:
    !> Why are you even bothering to use ASP.NET in the first place?
    !> Why not just use ASP Classic?

    Because ASP.NET has more than 3 times the throughput of "ASP Classic" ?




    Juan T. Llibre, asp.net MVP
    ¿ Estas probando VS 2010 y ASP.NET 4.0 ?
    Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
    http://asp.net.do/foros/forums/
    =====================================================
    "David Jackson" <> wrote in message news:...
    > "Luigi" <> wrote in message news:...
    >
    >>> That is one of the stupidest things I've heard in a long time!
    >>>
    >>> How can you take someone like that seriously?
    >>>
    >>> Time to look for another job?

    >>
    >> The entire application - ASP.NET MVC type - has many .ascx pages, with no
    >> code-behind, and *only* HTML controls (like <input type=etc....)

    >
    > An ASP.NET app which is not permitted to use webcontrols is plain ridiculous!
    >
    > Why are you even bothering to use ASP.NET in the first place? Why not just use ASP Classic?
     
    Juan T. Llibre, Jun 12, 2009
    #15
  16. "Juan T. Llibre" <> wrote in message
    news:...

    > !> An ASP.NET app which is not permitted to use webcontrols is plain
    > ridiculous!
    >
    > ASP.NET, using MVC, can use web controls.


    I know that, Juan, but Luigi isn't permitted to use them because of the
    ridiculous restriction imposed upon him by his project manager.

    > You need to understand what MVC is...


    Maybe you should have read the entire thread.
     
    David Jackson, Jun 12, 2009
    #16
  17. re:
    !> Maybe you should have read the entire thread.

    I did, but the restriction imposed on him is to
    not use code-behind, not to use code at all.

    He can, perfectly well, use inline code to do what must be done.
    That works around the restriction on code-behind imposed on him.




    Juan T. Llibre, asp.net MVP
    ¿ Estas probando VS 2010 y ASP.NET 4.0 ?
    Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
    http://asp.net.do/foros/forums/
    =====================================================
    "David Jackson" <> wrote in message news:...
    > "Juan T. Llibre" <> wrote in message news:...
    >
    >> !> An ASP.NET app which is not permitted to use webcontrols is plain ridiculous!
    >>
    >> ASP.NET, using MVC, can use web controls.

    >
    > I know that, Juan, but Luigi isn't permitted to use them because of the ridiculous restriction imposed upon him by his
    > project manager.
    >
    >> You need to understand what MVC is...

    >
    > Maybe you should have read the entire thread.
     
    Juan T. Llibre, Jun 12, 2009
    #17
  18. "Juan T. Llibre" <> wrote in message
    news:...

    > re:
    > !> Maybe you should have read the entire thread.
    >
    > I did, but the restriction imposed on him is to
    > not use code-behind, not to use code at all.


    You must have forgotten the post which included:

    "The entire application - ASP.NET MVC type - has many .ascx pages, with no
    code-behind, and *only* HTML controls (like <input type=etc....), and I have
    to accomplish this issue following this structure."

    Do you not consider that restricting an ASP.NET app (MVC or otherwise) to
    using only HTML controls is ridiculous?
     
    David Jackson, Jun 12, 2009
    #18
  19. re:
    !> "The entire application - ASP.NET MVC type - has many .ascx pages,
    !> with no code-behind, and *only* HTML controls (like <input type=etc....)
    !> Do you not consider that restricting an ASP.NET app
    !> (MVC or otherwise) to using only HTML controls is ridiculous?

    Just because there are no web controls used, so far, doesn't meant they can't be used.




    Juan T. Llibre, asp.net MVP
    ¿ Estas probando VS 2010 y ASP.NET 4.0 ?
    Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
    http://asp.net.do/foros/forums/
    =====================================================
    "David Jackson" <> wrote in message news:...
    > "Juan T. Llibre" <> wrote in message news:...
    >
    >> re:
    >> !> Maybe you should have read the entire thread.
    >>
    >> I did, but the restriction imposed on him is to
    >> not use code-behind, not to use code at all.

    >
    > You must have forgotten the post which included:
    >
    > "The entire application - ASP.NET MVC type - has many .ascx pages, with no
    > code-behind, and *only* HTML controls (like <input type=etc....), and I have
    > to accomplish this issue following this structure."
    >
    > Do you not consider that restricting an ASP.NET app (MVC or otherwise) to using only HTML controls is ridiculous?
     
    Juan T. Llibre, Jun 12, 2009
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    895
    Sudsy
    Aug 3, 2003
  2. Sydex
    Replies:
    12
    Views:
    6,528
    Victor Bazarov
    Feb 17, 2005
  3. RichB
    Replies:
    7
    Views:
    5,760
    dkmorris1999
    Sep 21, 2009
  4. Crazy Cat
    Replies:
    1
    Views:
    696
    schepp
    Sep 3, 2009
  5. Parthiv Joshi
    Replies:
    1
    Views:
    731
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page