you need to return true value from javascript function you are invoking. The page will be post back to the server if javascript function returns true at the end.
By default javascript function will return false, that is why your page is not posting back the data.
here is an example:
<input type="submit" önclick="return doSomething();" />
<script>
function doSomething()
{
''do something...
return true;
}
</script>
Hope this will help
Thanks,
hemant
Edit:
btntest.Attributes.Add("onclientclick", "javascript:ModalPopupsConfirm('" + hdnmin.ClientID + "','" + Pdtdesc.ClientID + "');return false;");
There are 2 problems with your code:
1- onclientclick:
The Problem:
OnClientClick
is a asp.net button's server side property it can't be added like this, while
Attributes
collection keeps attributes to be rendered for client end as-it-is. The above line will generate something like below for client:
<input type="Submit" önclientclick="javascript:ModalPopupsConfirm('" + hdnmin.ClientID + "','" + Pdtdesc.ClientID + "');return false;" />
The
onclientclick
in the above client code should be
onClick
The Solution: you need to modify your code to add onClick attribute instead of onclientclick, like this:
btntest.Attributes.Add("onClick","...your javascript code....");
or
btntest.OnClientClick = "javascript:ModalPopupsConfirm('" + hdnmin.ClientID + "','" + Pdtdesc.ClientID + "');return false;"
The above code will make sure your Javascript gets executed but it wont guarantee that
itemcommand
event will be raised because there is a problem in your javascript that wont allow your button to post current page back to server i.e. no postback. To solve it see Problem and solution 2.
2- Javascript:
javascript:ModalPopupsConfirm('" + hdnmin.ClientID + "','" + Pdtdesc.ClientID + "');return false;
The problem: The above code is identical to below javascript function:
function OnClickFunction()
{
ModalPopupsConfirm('" + hdnmin.ClientID + "','" + Pdtdesc.ClientID + "');
return false;
}
When you will click on the button, 2 statements will be executed first the
ModalPopupsConfirm
function and then
return false
. Because at the end you are returning false you are asking your browser to not submit your page because of some validation failure on button click.
The Solution:
The logic of your page demands: if user clicks yes in the pop-up post the page back and raise the itemcommand event but if user says no to the confirm pop-up don't do anything and stays on the page.
2.1 - Remove
return false
2.2 - Return proper bool from ModalPopupsConfirm function. (
i'm not sure about this i dont' work with ajax modal popup)
function ModalPopupsConfirm(hidden, Pdtdesc) {
var ItemCount = gethdnvalue(hidden);
var ProductName = document.getElementById(Pdtdesc).innerHTML;
document.getElementById(hidden).value = ItemCount;
return ModalPopups.Confirm("idConfirm1",
"Confirm your Order",
"<div style='padding: 25px; width:300px'>You Selected " + ItemCount + " Items For " + ProductName + "<br></br>Are you sure?</div>",
{
yesButtonText: "Yes",
noButtonText: "No",
onYes: "ModalPopupsConfirmYes()",
onNo: "ModalPopupsConfirmNo()"
}
);
add
return
before
ModalPopups.Confirm..
. code
2.3 - add return before javascript function call in Attributes.Add or OnClientClick
btntest.Attributes.Add("onClick", "return ModalPopupsConfirm('" + hdnmin.ClientID + "','" + Pdtdesc.ClientID + "');");
or
btntest.OnClientClick = "return ModalPopupsConfirm('" + hdnmin.ClientID + "','" + Pdtdesc.ClientID + "');";
Final Solution:
implement the changes in point 2 i.e. from 2.1 to 2.3
Additional Link:
there is an article doing exactly what you want to achieve. i'm adding it for an example and because i'm not sure how
ModalPopup
works at client end:
http://mattberseth.com/blog/2007/07/confirm_gridview_deletes_with.html[
^]
Hope this will resolve your issue and help you better understand about how things gets processed.
Thanks,
Hemant