Do all ASP buttons do submit?

R

Randall Parker

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?
 
U

Usenet Honey Pot

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
 
J

Jason Kester

Randall said:
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/
 
R

Randall Parker

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.
 
J

Jason Kester

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

That's just HTML:
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/
 
R

Randall Parker

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.
 
J

Jason Kester

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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top