Note : Below problem is both in AJAX & Non-AJAX
Let say you have a drop down. You have a JS attached with it.
// ------------------------------------------------------------------------------------------------------------------------
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" CausesValidation="True" onchange="return Validate();" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>aa</asp:ListItem>
<asp:ListItem>bb</asp:ListItem>
<asp:ListItem>cc</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="" OnClick="Button1_Click" Visible="True" /> // Will be hidden button
// ------------------------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------------
<script type="text/javascript">
function Validate()
{
num = 6; // Here, could be any compelx logic.
if(num > 5)
return true;
else
return false;
}
</script>
// ------------------------------------------------------------------------------------------------------------------------
What is wrong:
When you change some selection in dropdown, then JavaScript fires and returns ‘ true’. Now though it returns ‘true’ the Server side event does not fires.
Hence you need to change the script as below.
function Validate()
{
num = 6; // Here, could be any compelx logic.
if(num > 5)
{
// return true; // Comment it.
var hiddenButton=document.getElementById('<%= Button1.ClientID %>');
hiddenButton.click();
}
else
return false;
}
</script>
Solution Required:
Need some good Solution. Please help.
Thanks & Regards,
Arun Manglick
SMTS || Microsoft Technology Practice || Bridgestone - Tyre Link || Persistent Systems || 3023-6258
DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.
No comments:
Post a Comment