Do all ASP buttons do submit?

Discussion in 'ASP .Net' started by Randall Parker, Oct 29, 2005.

  1. I'm looking at this web page:
    http://www.allasp.net/enterkey.aspx

    Where they say:

    Remember:

    * <asp:Button> controls render as <input type=submit value=xxx> html elements.
    * <asp:HtmlInputButton> controls render as <input type=button value=xxx
    onclick=__doPostBack(...)> html elements.
    * <asp:HtmlButton> controls render as <button onclick=__doPostBack(...)>xxx</button>

    Okay, the first case does a submit. The other two cases do the __doPostBack() calls
    which presumably also do submits. The main difference between the Button on one hand
    and tht HtmlInputButton and HtmlButton on the other hand is that the latter two will
    cause IsPostBack to test as true in the CodeBehind. But they all cause a submit, right?

    Suppose one wants to have a button that does not cause a submit of the current page
    and that instead goes an HTML GET to another URL. Is there a way to do that with some
    asp: button control?

    What I want to do: have rows in a DataGrid with buttons to click to various other
    pages. I guess I could do that via a CodeBehind redirect. But why go thru that
    overhead on the server? Doesn't that redirect require an additional handshake between
    the browser and server where the server has to tell the browser to do an HTML GET?

    So how to describe that buttons in a grid column should go to links without submit
    happening?
     
    Randall Parker, Oct 29, 2005
    #1
    1. Advertising

  2. Randall Parker <NOtechieSPAMpundit_please@future_avoidjunk_pundit.com>
    wrote in news::

    > Suppose one wants to have a button that does not cause a submit of the
    > current page and that instead goes an HTML GET to another URL. Is
    > there a way to do that with some asp: button control?


    Take a look at the HTML Controls (HTMLButton) rather than web controls -
    HTML controls allow you to render generic controls without all the HTML
    add-ons.

    As for plain hyperlinks... I think you need to use HTMLGenericControl:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-
    us/cpref/html/frlrfsystemwebuihtmlcontrols.asp

    --
    Stan Kee ()
     
    Usenet Honey Pot, Oct 29, 2005
    #2
    1. Advertising

  3. Randall Parker

    Jason Kester Guest

    Randall Parker wrote:
    > I'm looking at this web page:
    > http://www.allasp.net/enterkey.aspx
    >
    > Where they say:
    >
    > Remember:
    >
    > * <asp:Button> controls render as <input type=submit value=xxx> html elements.
    > * <asp:HtmlInputButton> controls render as <input type=button value=xxx
    > onclick=__doPostBack(...)> html elements.
    > * <asp:HtmlButton> controls render as <button onclick=__doPostBack(...)>xxx</button>
    >
    > Okay, the first case does a submit. The other two cases do the __doPostBack() calls
    > which presumably also do submits. The main difference between the Button on one hand
    > and tht HtmlInputButton and HtmlButton on the other hand is that the latter two will
    > cause IsPostBack to test as true in the CodeBehind. But they all cause a submit, right?


    They all do exactly the same thing. All will post back unless you tell
    them not to. All will trip the IsPostBack flag. All can have events
    hooked up to them. The only reason that <asp:Button> and its friends
    exist at all is the vain hope that maybe you'll forget what an actual
    HTML tag looks like and be forced to continue using ASP.NET forever.

    The fact that you bothered to read up on the issue shows that you're
    not one to drink the Microsoft Cool Aid without first learning what's
    in it. For you, I'd recommend <input type=submit runat=server>.

    Good luck!

    Jason Kester
    Expat Software Consulting Services
    http://www.expatsoftware.com/

    ---
    Get your own Travel Blog, with itinerary maps and photos!
    http://www.blogabond.com/
     
    Jason Kester, Oct 30, 2005
    #3
  4. How do you tell them not to post back? Is there some attribute in a flag?

    I'm looking at the members of HtmlInputButton and so not see a property that looks
    like it suppresses postback. Is there one?

    Also, you refer to:
    <input type=submit runat=server>

    Why would one put runat=server on a tag that will become an HTML page tag? The input
    tag is not asp:input. It is just plain input. I thought runat=server was only used
    for tags that you want the ASP.Net pre-processor to translate into something else.

    Though I'm an ASP.Net novice and I still do not understand some basics. So maybe I'm
    wrong.

    Jason Kester wrote:
    >
    > They all do exactly the same thing. All will post back unless you tell
    > them not to. All will trip the IsPostBack flag. All can have events
    > hooked up to them. The only reason that <asp:Button> and its friends
    > exist at all is the vain hope that maybe you'll forget what an actual
    > HTML tag looks like and be forced to continue using ASP.NET forever.
    >
    > The fact that you bothered to read up on the issue shows that you're
    > not one to drink the Microsoft Cool Aid without first learning what's
    > in it. For you, I'd recommend <input type=submit runat=server>.
    >
    > Good luck!
    >
    > Jason Kester
    > Expat Software Consulting Services
    > http://www.expatsoftware.com/
    >
    > ---
    > Get your own Travel Blog, with itinerary maps and photos!
    > http://www.blogabond.com/
    >
     
    Randall Parker, Oct 30, 2005
    #4
  5. Randall Parker

    Jason Kester Guest

    Randall Parker wrote:
    > How do you tell them not to post back? Is there some attribute in a flag?


    That's just HTML:
    <input type="button" onclick="myClientSideFunction()">

    > Also, you refer to:
    > <input type=submit runat=server>
    >
    > Why would one put runat=server on a tag that will become an HTML page tag? The input
    > tag is not asp:input. It is just plain input. I thought runat=server was only used
    > for tags that you want the ASP.Net pre-processor to translate into something else.


    No. runat=server is available for any HTML tag. <br id="myBR"
    runat=server/> is perfectly valid, and will be available to you as a
    HtmlGenericControl on the server.

    Take a look at the HTML generated by <asp:button> for an answer to your
    question. It will render as <input type=submit>, plus a bunch of
    script. The question you will eventually want to ask youself is, since
    it's rendering as an INPUT anyway, why not declare it as one?


    > Though I'm an ASP.Net novice and I still do not understand some basics. So maybe I'm
    > wrong.


    Try to learn a bit about HTML and CGI programming outside of the
    context of ASP.NET. Seriously, install Perl or PHP on a server and
    write some simple database tools. It will take away a lot of
    misconceptions about the things that ASP.NET is doing for you behind
    the scenes.


    Jason Kester
    Expat Software Consulting Services
    http://www.expatsoftware.com/

    ---
    Get your own Travel Blog, with itinerary maps and photos!
    http://www.blogabond.com/


    >
     
    Jason Kester, Oct 30, 2005
    #5
  6. Jason,

    I think I finally understand: So you are saying that HtmlGenericControl is a class on
    the server-side that does not match the name of an ASP.Net tag? You just assign
    runat=server to a normal HTML tag and then you can access that tag in CodeBehind by
    declaring a variable with the same name as its ID?

    Yes, if one can do that then some of the ASP.Net tags become a lot less necessary.
    Plus, one gets more control over what gets produced.

    Jason Kester wrote:

    > No. runat=server is available for any HTML tag. <br id="myBR"
    > runat=server/> is perfectly valid, and will be available to you as a
    > HtmlGenericControl on the server.
    >
    > Take a look at the HTML generated by <asp:button> for an answer to your
    > question. It will render as <input type=submit>, plus a bunch of
    > script. The question you will eventually want to ask youself is, since
    > it's rendering as an INPUT anyway, why not declare it as one?
     
    Randall Parker, Oct 31, 2005
    #6
  7. Randall Parker

    Jason Kester Guest

    Exactly. Most tags that you'll actually want to touch from the server
    will have their own HtmlControl equivilant (HtmlAnchor, HtmlInputText,
    HtmlTableRow, etc.) The rest can still be dealt with as
    HtmlContainerControl or HtmlGenericControl objects.

    The only <asp:...> tags that I use on a regular basis are the helpers
    such as Repeater and DataGrid, and the occasional Literal. There are
    certain specific (and very rare) cases where <asp:button> is more
    useful than <input type="button" runat=server>, but for the most part I
    prefer my Html to look like Html.

    Jason Kester
    Expat Software Consulting Services
    http://www.expatsoftware.com/


    ---
    Get your own Travel Blog, with itinerary maps and photos!
    http://www.blogabond.com/
     
    Jason Kester, Oct 31, 2005
    #7
    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. D. Shane Fowlkes
    Replies:
    3
    Views:
    631
    S. Justin Gengo
    Feb 24, 2004
  2. Ghafran Abbas
    Replies:
    0
    Views:
    4,249
    Ghafran Abbas
    Oct 12, 2004
  3. Roger
    Replies:
    1
    Views:
    642
    GreggTB
    May 20, 2005
  4. Replies:
    1
    Views:
    5,124
    Darren Kopp
    Feb 22, 2006
  5. Replies:
    4
    Views:
    950
Loading...

Share This Page