Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<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()"/>
Posted
Updated 23-Feb-15 8:21am
v3

1 solution

The problem is that the second function isn't available in the global scope. Instead, you've passed a named function to the jQuery function, which will call the passed function when the document has been parsed.

Change the second function declaration to:
JavaScript
// NB: Remove the "$(" here:
function ValidatePg() {
   
   ...
   
// NB: Remove the ");" here:
}
 
Share this answer
 
Comments
nuthi_naresh 24-Feb-15 0:56am    
even then i am not able to resolve the issue
Richard Deeming 24-Feb-15 7:30am    
Then you'll need to debug the code and check for any script errors.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900