I Have two buttons in my page and two buttons fire different onclientclick events.. here is my code and only the first button fires the event please suggest me how to solve this.... <asp:Button ID="btnUpload" CssClass="myButton" runat="server" OnClick="btnUpload_Click" Text="Import Email Id's" OnClientClick="return ValidateFile()"/> <script type="text/javascript"> // var validFilesTypes = ["bmp", "gif", "png", "jpg", "jpeg", "doc", "xls"]; var validFilesTypes = [
"xls",
"xlsx"];
function ValidateFile() {
var file = document.getElementById(
"<%=FileUpload2.ClientID%>");
var label = document.getElementById(
"<%=Label1.ClientID%>");
var path = file.value;
var ext = path.substring(path.lastIndexOf(
".") +
1, path.length).toLowerCase();
var isValidFile =
false;
for (
var i =
0; i < validFilesTypes.length; i++) {
if (ext == validFilesTypes[i]) { isValidFile =
true;
break; } }
if (!isValidFile) { $(
function ShowPopup(message) { $(
function () {
var message =
"Invalid File. Please upload a File with" +
" extension:\n\n" + validFilesTypes.join(
", "); $(
"#dialog").html(message); $(
"#dialog").dialog({ title:
"Error", buttons: { Close:
function () { $(
this).dialog(
'close'); } }, modal:
true }); }); }); label.style.color =
"red"; label.innerHTML =
"Invalid File. Please upload a File with" +
" extension:\n\n" + validFilesTypes.join(
", "); }
return isValidFile; }
</script> <script type="text/javascript"> $(
function ValidatePg() {
var ToEmail = document.getElementById(
'<%=TxtTO.ClientID %>').value;
var Subject = document.getElementById(
'<%=TxtSubject.ClientID %>').value;
if (TxtTO ==
"") { alert(
"No Email id Choosen, Please Enter Email ID"); document.getElementById(
'<%=TxtTO.ClientID %>').focus();
return false; }
if (TxtSubject ==
"") {
var message =
"EnterSubject"; ShowPopup(message); alert(
"EnterSubject"); document.getElementById(
'<%=TxtSubject.ClientID %>').focus();
return false; } label.style.color =
"red"; label.innerHTML =
"Invalid File. Please upload a File with"; });
</script> <asp:Button ID="Btn_Send" CssClass="myButton" runat="server" Text="Send" OnClick="Btn_Send_Click" OnClientClick="return ValidatePg()"/><asp:Button ID="btnUpload" CssClass="myButton" runat="server" OnClick="btnUpload_Click" Text="Import Email Id's" OnClientClick="return ValidateFile()"/> <script type="text/javascript"> // var validFilesTypes = ["bmp", "gif", "png", "jpg", "jpeg", "doc", "xls"]; var validFilesTypes = ["xls", "xlsx"]; function ValidateFile() { var file = document.getElementById("<%=FileUpload2.ClientID%>"); var label = document.getElementById("<%=Label1.ClientID%>"); var path = file.value; var ext = path.substring(path.lastIndexOf(".") + 1, path.length).toLowerCase(); var isValidFile = false; for (var i = 0; i < validFilesTypes.length; i++) { if (ext == validFilesTypes[i]) { isValidFile = true; break; } } if (!isValidFile) { $(function ShowPopup(message) { $(function () { var message = "Invalid File. Please upload a File with" + " extension:\n\n" + validFilesTypes.join(", "); $("#dialog").html(message); $("#dialog").dialog({ title: "Error", buttons: { Close: function () { $(this).dialog('close'); } }, modal: true }); }); }); label.style.color = "red"; label.innerHTML = "Invalid File. Please upload a File with" + " extension:\n\n" + validFilesTypes.join(", "); } return isValidFile; } </script> <script type="text/javascript"> $(function ValidatePg() { var ToEmail = document.getElementById('<%=TxtTO.ClientID %>').value; var Subject = document.getElementById('<%=TxtSubject.ClientID %>').value; if (TxtTO == "") { alert("No Email id Choosen, Please Enter Email ID"); document.getElementById('<%=TxtTO.ClientID %>').focus(); return false; } if (TxtSubject == "") { var message = "EnterSubject"; ShowPopup(message); alert("EnterSubject"); document.getElementById('<%=TxtSubject.ClientID %>').focus(); return false; } label.style.color = "red"; label.innerHTML = "Invalid File. Please upload a File with"; }); </script> <asp:Button ID="Btn_Send" CssClass="myButton" runat="server" Text="Send" OnClick="Btn_Send_Click" OnClientClick="return ValidatePg()"/>