Home > Archive > ASP .NET > October 2005 > Do all ASP buttons do submit?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Do all ASP buttons do submit?
|
|
| Randall Parker 2005-10-29, 7:02 pm |
| 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?
| |
| Usenet Honey Pot 2005-10-29, 7:02 pm |
| Randall Parker < NOtechieSPAMpundit_please@future_avoidju
nk_pundit.com>
wrote in news:e7yC1JN3FHA.3944@TK2MSFTNGP10.phx.gbl:
> 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/d...rl=/library/en-
us/cpref/html/frlrfsystemwebuihtmlcontrols.asp
--
Stan Kee (spamhoneypot@rogers.com)
| |
| Jason Kester 2005-10-29, 9:56 pm |
|
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/
| |
| Randall Parker 2005-10-30, 7:00 pm |
| 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/
>
| |
| Jason Kester 2005-10-30, 7:00 pm |
| 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/
>
| |
| Randall Parker 2005-10-31, 7:02 pm |
| 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?
| |
| Jason Kester 2005-10-31, 7:02 pm |
| 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/
|
|
|
|
|