On Client click is not running as expected
Dear All
I have weired situation i just wrote a simple java script function whichh will return true or false
even when the function returns false my server side button click event was firing.
this is not happening regullarly
i am using vs 2010 and ie 8 and vb.net 3.5
this is not happening all the time , please tell me your sugegstions
please check my below code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ViewRateCard.aspx.vb" Inherits="ViewRateCard" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width:15%;
}
.style2
{
width: 10%;
}
</style>
<script type="text/javascript">
function popNewRateWindow() {
var url;
var left = (screen.width / 2) - (400 / 2);
var top = (screen.height / 2) - (400 / 2);
url = 'http://localhost:6500/merabell/newRateCard.aspx';
newwindow = window.open(url, 'name', 'height=200,width=150,top=' + top + ', left=' + left);
//newwindow = window.open(url, 'name', 'height=700,width=800,top='+top+', left='+left);
if (window.focus) { newwindow.focus() }
document.getElementById('btnNew').disabled = true;
return false;
}
function validateDdlist() {
var validate = false;
var val;
var intext
val = document.getElementById('ddlRateCard').value;
if (val > -1) {
validate = true;
} else {
}
val = document.getElementById('ddlAdSize').value;
if (val > -1 && validate == true) {
validate = true;
} else {
validate = false;
}
val = document.getElementById('ddlAdColor').value;
if (val > -1 && validate == true) {
validate = true;
} else {
validate = false;
}
val = document.getElementById('ddlAdFreq').value;
if (val > -1 && validate == true) {
validate = true;
} else {
validate = false;
}
val = document.getElementById('ddlAdPos').value;
if (val > -1 && validate == true) {
validate = true;
} else {
validate = false;
}
val = document.getElementById('txtRate').value;
if (parseInt(val) > 0 && parseInt(val) != 'NaN' && validate == true) {
validate = true;
} else {
validate = false;
}
alert(validate);
if (validate == false) {
document.getElementById('divErr').innerHTML = "Please Fill The Mandatory Fields with Correct Values";
return validate;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="Scriptmanager1" runat="server">
</asp:ScriptManager>
<table width="100%" >
<tr>
<td colspan="6" align="center">
Test Project
</td>
</tr>
<tr>
<td class="style2" align="right">
<div id="div1" runat="server">
*</div>
</td>
<td class="style1" align="left">
Rate Card:
</td>
<td class="style1">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlRateCard" AutoPostBack="true" runat="server">
<asp:ListItem Selected="True" Value="-1">Create or Select Rate Card</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td class="style2" align="right">
<div id="div2" runat="server">
*</div>
</td>
<td class="style1" align="left">
Ad Rate:
</td>
<td class="style1">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtRate" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td class="style2" align="right">
<div id="div3" runat="server">
*</div>
</td>
<td align="left">
Ad Size:
</td>
<td align="left">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlAdSize" runat="server">
<asp:ListItem Selected="True">Select Ad Size</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td class="style2" align="right">
<div id="div4" runat="server">
*</div>
</td>
<td align="left">
Ad Color:
</td>
<td align="left">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlAdColor" runat="server">
<asp:ListItem Selected="True">Select Ad Color</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td class="style2" align="right">
<div id="div5" runat="server">
*</div>
</td>
<td align="left">
Ad Frequency:
</td>
<td align="left">
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlAdFreq" runat="server">
<asp:ListItem Selected="True">Select Ad Frequency</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td class="style2" align="right">
<div id="div6" runat="server">
*</div>
</td>
<td align="left">
Ad Position:
</td>
<td align="left">
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlAdPos" runat="server">
<asp:ListItem Selected="True">Select Ad Positon</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td align="left">
</td>
<td colspan="2" align="center">
</td>
<td align="left">
</td>
</tr>
<tr>
<td colspan="6" align="center">
<div id="divErr" runat="server">
</div>
</td>
</tr>
<tr>
<td align="left">
</td>
<td align="center">
<asp:Button ID="btnNew" runat="server" Text="New Rate Card" OnClientClick="return popNewRateWindow();" />
</td>
<td align="left">
<asp:Button ID="btnSave" runat="server" Text="Save Rate Card" OnClientClick="return validateDdlist();" OnClick="btnSave_Click" />
</td>
<td align="left">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
even i removed OnClick="btnSave_Click" still the problem is persisting ,please do the need full
thanks in advance
Re: On Client click is not running as expected
You really should use code tags so as to make your code retain formatting and be somewhat readable, Also you should post questions related to Java Script in the area for Java script rather than VB area.