Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

Do all ASP buttons do submit?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Randall Parker - 29 Oct 2005 22:48 GMT
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 - 29 Oct 2005 23:32 GMT
> 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

Signature

Stan Kee (spamhoneypot@rogers.com)

Jason Kester - 30 Oct 2005 03:41 GMT
> I'm looking at this web page:
> http://www.allasp.net/enterkey.aspx
[quoted text clipped - 12 lines]
> 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 - 30 Oct 2005 23:48 GMT
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.

> 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
[quoted text clipped - 15 lines]
> Get your own Travel Blog, with itinerary maps and photos!
> http://www.blogabond.com/
Jason Kester - 31 Oct 2005 00:43 GMT
> 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 - 31 Oct 2005 18:40 GMT
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.

> 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
[quoted text clipped - 4 lines]
> 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 - 31 Oct 2005 19:22 GMT
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/

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.