两个OnclientClick可以在一个页面上触发吗? [英] Can two OnclientClick fires on a single page?

查看:103
本文介绍了两个OnclientClick可以在一个页面上触发吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有两个按钮,两个按钮触发不同的onclientclick事件..这是我的代码,只有第一个按钮触发事件

请建议我如何解决这个问题....

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()"/>

推荐答案

function ShowPopup(message){
(function ShowPopup(message) {


function () {
var message = 无效文件。请上传一个文件,其中包含 + extension:\ n\\\
+ validFilesTypes.join( );
(function () { var message = "Invalid File. Please upload a File with" + " extension:\n\n" + validFilesTypes.join(", ");


(< span class =code-string> #dialog)。html(message);
("#dialog").html(message);


这篇关于两个OnclientClick可以在一个页面上触发吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆