Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在单击按钮时从codebehind调用多个javascript函数。对于3个javascript函数,它可以正常工作,但仅此而已_Javascript_C# - Fatal编程技术网

我想在单击按钮时从codebehind调用多个javascript函数。对于3个javascript函数,它可以正常工作,但仅此而已

我想在单击按钮时从codebehind调用多个javascript函数。对于3个javascript函数,它可以正常工作,但仅此而已,javascript,c#,Javascript,C#,我需要从asp.net页面的codebehind页面调用4个java脚本函数,这对于3个javascript函数很好,但如果我添加第4个,这是一个验证函数。验证功能有效,但其他3个功能无效 这管用 btnSubmit.OnClientClick = "return Getprodsize('" + hdnprdsize.ClientID + "');return formatSpecifications('" + hdnSpecifications.ClientID + "');return G

我需要从asp.net页面的codebehind页面调用4个java脚本函数,这对于3个javascript函数很好,但如果我添加第4个,这是一个验证函数。验证功能有效,但其他3个功能无效

这管用

btnSubmit.OnClientClick = "return Getprodsize('" + hdnprdsize.ClientID + "');return formatSpecifications('" + hdnSpecifications.ClientID + "');return Getselectedvalue('" + hdndrop.ClientID + "')";
这不管用

btnSubmit.OnClientClick = "return Validate();Getprodsize('" + hdnprdsize.ClientID + "');return formatSpecifications('" + hdnSpecifications.ClientID + "');return Getselectedvalue('" + hdndrop.ClientID + "')";
功能验证{ var existing=$ctl00\u contentMain\u lblProductleft.text; 如果$'ctl00\u contentMain\u txtProductName'.val=={ $'ctl00\u contentMain\u txtProductName'.focus.cssborder-color,红色; 返回false; } 如果$'ctl00\u contentMain\u Txtbrandname'.val=={ $'ctl00\u contentMain\u Txtbrandname'.focus.cssborder-color,红色; 返回false; } 如果$'ctl00\u contentMain\u Txtstock'.val=={ $'ctl00\u contentMain\u Txtstock'.focus.cssborder-color,红色; 返回false; } 如果$'ctl00\u contentMain\u Txtprice'.val=={ $'ctl00\u contentMain\u Txtprice'.focus.cssborder-color,红色; 返回false; } 如果$'ctl00\u contentMain\u txtShortDescription'.val=={ $'ctl00\u contentMain\u txtShortDescription'.focus.cssborder-color,红色; 返回false; } 如果$'ctl00\u contentMain\u txtLongDescription'.val=={ $'ctl00\u contentMain\u txtLongDescription'.focus.cssborder-color,红色; 返回false; } 如果$'ctl00\u contentMain\u ddlbcatgory选项:选中'.val==0{ 请选择类别; 返回false; } 如果$'ctl00\u contentMain\u txtdeleverycharge'.val==0{ $'ctl00\u contentMain\u txtdeleverycharge'.focus.cssborder-color,红色; 返回false; } var txval=$'input[name=optradio]:选中'.val; $.valtxval; 返回true; } onClientClick属性中不能有多个return语句。第一个将返回,其余将不执行。您应该在不使用return的情况下调用其他函数,然后从Validate函数返回值

btnSubmit.OnClientClick = "Getprodsize('" + hdnprdsize.ClientID + "'); formatSpecifications('" + hdnSpecifications.ClientID + "'); Getselectedvalue('" + hdndrop.ClientID + "'); return Validate();";
如果您想先检查验证,如果验证失败则不调用其他函数,那么可以使用If

如果您将所有这些逻辑移到一个新函数中,并且只在OnClientClick中调用该函数,则会更容易

    btnSubmit.OnClientClick = "if(Validate()) {Getprodsize('" + hdnprdsize.ClientID + "'); formatSpecifications('" + hdnSpecifications.ClientID + "'); Getselectedvalue('" + hdndrop.ClientID + "'); return true;} else return false";
function validateAndFormat(sizeID, specID, dropID) {
    if(Validate()) {
        Getprodsize(sizeID); 
        formatSpecifications(specID); 
        Getselectedvalue(dropID); 
        return true;
    } else {
        return false
    }
}

btnSubmit.OnClientClick = "validateAndFormat('" + hdnprdsize.ClientID + "', '" + hdnSpecifications.ClientID + "' + "', '" + hdndrop.ClientID + "');"