Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nate 143 posts 184 karma points
    Oct 25, 2011 @ 20:59
    Nate
    0

    Postbacks with Razor?

    I freaking LOVE razor over user controls, but when my page gets complex, I have to revert.

    For example, I have a page with two buttons on it.  One button for a user to suspend their account, and another for the user to delete their account.

    Is there a way with razor to get the server to pick up these post backs?  I'm guessing I might be stuck with jquery/webservices or maybe querystring URLS.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 25, 2011 @ 21:01
    Dirk De Grave
    0

    Yup, use

    @if (IsPost) {
    //...
    }

     

    Cheers,

    /Dirk 

  • Nate 143 posts 184 karma points
    Oct 25, 2011 @ 21:17
    Nate
    0

    That's just telling you if there is a post back.  I'm trying to do a MVC thing of posting the page to a controller, but I don't think that's possible.

  • Nate 143 posts 184 karma points
    Oct 25, 2011 @ 21:31
    Nate
    0

    oo, i was looking into what you were saying and it's not isPostBack, sorry I was confused.

    I'm not getting my buttons to postback though.  I have this <input type="button" value="Suspend Account"/>

    When i click on that, the page should postback, correct? Am I missing something?

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 25, 2011 @ 21:35
    Dirk De Grave
    0

    well, you still need a form and you need

    <input type="submit" value="Suspend account" />

    in order to perform a postback

     

    Cheers,

    /Dirk

  • Nate 143 posts 184 karma points
    Oct 25, 2011 @ 21:37
    Nate
    0

    haha, opps!  Yah, submit works.


    One last question, how do I see the data that was in the fields in the form or tell which button was clicked?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 25, 2011 @ 21:40
    Dirk De Grave
    0

    Just as you would with *webforms*, just check Request["nameOfInputField"] and I think your submit button will contain the text you've specified, so

    Request["nameOfSubmitButton"] == "Suspend Account"

    (Btw, you'll have to add the attribute name in your submit button...)

    Cheers,

    /Dirk

  • Nate 143 posts 184 karma points
    Oct 25, 2011 @ 21:46
    Nate
    0

    Sweet!  That works! Thansk so much!  You just made my life 100x easier!

    How do I tell which button submited the form?

    i.e. I have 

    <input type="button" name="btnSuspend" value="Suspend Account"/>

    <input type="button" name="btnCancel" value="Cancel Account"/>

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 25, 2011 @ 21:49
    Dirk De Grave
    1

    Easypeasy to find out, just write out both Request["btnSuspend"] and Request["btnCancel"] and find out what's being posted...

     

    Cheers,

    /Dirk

  • Nate 143 posts 184 karma points
    Oct 25, 2011 @ 21:51
    Nate
    1

    You sir, are a gentleman, a scholar and a badass.  Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft