HTML Button Not Submitting Page

A

Alphonse Giambrone

Thanks to info from Steven Cheng I am able to use an HTML button on my aspx
page in order to wrap text in it.
I am using it to delete a record in a database and it works.
My only problem is that I want to include javascript to confirm the deletion
before submitting.
I have a javascript function that prompt for confirmation and returns
true/false.
For a regular server side button I add it as follows in the page load event
and it works fine:

btnDelete.Attributes.Add("onclick", "return ConfirmDelete();")

However if I add it the same way to the HTML button, the prompt works, but
the page is not submitted.
Looking at the source, this is what is rendered for the event with and
without my added function:

onclick="return ConfirmDelete(); {if (typeof(Page_ClientValidate) !=
'function' || Page_ClientValidate())
__doPostBack('U_PageLinks1$btnDelete','')} "

onclick="{if (typeof(Page_ClientValidate) != 'function' ||
Page_ClientValidate()) __doPostBack('U_PageLinks1$btnDelete','')} "

Any suggestion on how I can confirm the delete and still submit the page?

TIA
 
G

Guest

I wasn't sure if return from Confirm call submitted the form when you had ClientSideValidation turned on?

My experience has been that if you have Clientsidevalidation set then .NET will wire the validation handler to the onclick method of the button. That event will override yours

But it's interesting you say that it confirms but doesn't submit. I would've expected the opposite

You may want to try setting CausesValidation for the HTMLButton to false and inside your handler method call Page_ClientValidate() and only return true if operation is confirmed and the page is validated

HTH
Suresh

----- Alphonse Giambrone wrote: ----

Thanks to info from Steven Cheng I am able to use an HTML button on my asp
page in order to wrap text in it
I am using it to delete a record in a database and it works
My only problem is that I want to include javascript to confirm the deletio
before submitting
I have a javascript function that prompt for confirmation and return
true/false
For a regular server side button I add it as follows in the page load even
and it works fine

btnDelete.Attributes.Add("onclick", "return ConfirmDelete();"

However if I add it the same way to the HTML button, the prompt works, bu
the page is not submitted
Looking at the source, this is what is rendered for the event with an
without my added function

onclick="return ConfirmDelete(); {if (typeof(Page_ClientValidate) !
'function' || Page_ClientValidate()
__doPostBack('U_PageLinks1$btnDelete','')}

onclick="{if (typeof(Page_ClientValidate) != 'function' |
Page_ClientValidate()) __doPostBack('U_PageLinks1$btnDelete','')}

Any suggestion on how I can confirm the delete and still submit the page

TI
 
N

Natty Gur

Hi,

HTML button is not server side control tus cant response to server side
events. so if 'U_PageLinks1$btnDelete' is the name of HTML control the
request will arive to the server but no event is set to handle this
request. you can check it by putting break point in Page_load event.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
B

bruce barker

you confirm delete code has to support validation and postback itself.

btnDelete.Attributes.Add("onclick", string.Format("return
ConfirmDelete('{0}');",btnDelete.UniqueId)


function ConfirmDelete(id)
{
if (window.confirm("really?")
&& (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate())
{
__doPostBack(id,'');
}
if (document.all) event.returnValue = false; // hack for ie bug
return false;
}


-- bruce (sqlwork.com)
 
A

Alphonse Giambrone

Thanks both for the quick replies.

Natty,
HTML controls are available and can raise events on server side by right
clicking on the control in design view and checking 'run as server control'.
As I stated in my original post it works until I add the additional
javascript call.

Suresh,
I tried adding CausesValidation="false" and that changed the rendered code
to:
onclick="return ConfirmDelete(); __doPostBack('U_PageLinks1$btnDelete','')"

However the page is still not submitted. It seems that for some reason the
designer generated code is not executing. Thniking about it, that is exactly
what is happening.

So, I changed the add attribute to :

btnDelete.Attributes.Add("onclick", "if(ConfirmDelete()==true)")

This renders on client as:
onclick="if(ConfirmDelete()==true)
__doPostBack('U_PageLinks1$btnDelete','')"

Now it works!

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


Suresh said:
I wasn't sure if return from Confirm call submitted the form when you had
ClientSideValidation turned on??
My experience has been that if you have Clientsidevalidation set then .NET
will wire the validation handler to the onclick method of the button. That
event will override yours.
But it's interesting you say that it confirms but doesn't submit. I
would've expected the opposite.
You may want to try setting CausesValidation for the HTMLButton to false
and inside your handler method call Page_ClientValidate() and only return
true if operation is confirmed and the page is validated.
 
A

Alphonse Giambrone

Bruce,

Thanks for the reply. My solution works also, but your helps me understand
it better.
 

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

Top