添加查询字符串时验证不工作 [英] Validation not working when adding query string

查看:161
本文介绍了添加查询字符串时验证不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的验证不工作C $ C> windows.location.href 。

My validations are not working when redirecting from one page to another on passing query string as a parameter with response.redirect or with windows.location.href.

当我从一个页面重定向到另一个页面,这样的:

When i am redirecting from one page to another page with this:

<asp:Button ID="New" runat="server" Text="New" OnClientClick="Transfer()" />

 function Transfer() {
        window.location.href = "Abc.aspx?flag=yes"; //when adding query string my validation doesnt work
        //window.location.href = "Abc.aspx";// When removing query string my validation successfully works
    }

然后,我已经从服务器端尝试这样的:

Then i have tried from server side like this:

<asp:Button ID="New" runat="server" Text="New" OnClick="New_Click" />
 protected void btnNewApplicant_Click(object sender, EventArgs e)
        {
            Response.Redirect("Abc.aspx?flag=yes", false); //again not working with this.
        }

当我点击这个按钮我得到的错误控制台:

When i click on this New button i am getting error in console:

这是错误与此选项可以做什么: EnableEventValidation =FALSE,你可以在我的code ??见

Is this error has to do anything with this option:EnableEventValidation="false" as you can see in my code??

注意:我需要传递参数作为查询字符串出于某种原因,

Note:I need to pass parameter as query string for some reason.

Abc.aspx

<%@ Page Title="" Theme="---" Language="C#" MasterPageFile="---" AutoEventWireup="true" CodeBehind="---" EnableEventValidation="false" Inherits="---" %>

     <asp:TextBox ID="txt1" runat="server"></asp:TextBox>
     <asp:RequiredFieldValidator ID="rf1" runat="server" ErrorMessage="require" ForeColor="Red" ControlToValidate="txt1" Display="None" ValidationGroup="validate"></asp:RequiredFieldValidator>

     <asp:TextBox ID="txt2" runat="server"></asp:TextBox>
     <asp:RequiredFieldValidator ID="rf2" runat="server" ErrorMessage="require" ForeColor="Red" ControlToValidate="txt2" Display="None" ValidationGroup="validate"></asp:RequiredFieldValidator>

<asp:Button ID="btnSubmit" runat="server" Text="Save" ValidationGroup="validate" OnClick="btnSubmit_Click" UseSubmitBehavior="true" OnClientClick="checkvalidation()"/> //on click of this i want to perform validation but it is not working.
<telerik:RadCodeBlock ID="radcodeblock1" runat="server" EnableViewState="true">
 <script type="text/javascript">
    function checkvalidation() {
            window.Page_ClientValidate('validate');
            var counter= 0;
            var val= '';
            for (var i = 0; i < window.Page_Validators.length; i++) {
                if (!window.Page_Validators[i].isvalid && typeof (window.Page_Validators[i].errormessage) == "string") {
                    counter= 1;
                    val+= '-  ' + window.Page_Validators[i].errormessage + '<br>';
                }
            }
            if (counter== 1) {
              //My validation pop up to display validations alert because this counter value remains 0 so this part is not executed.
            }
        }
 </script>
</telerik:RadCodeBlock>

现在,当我点击提交按钮,然后我的服务器端code事件被触发,但我的验证弹出doenst出现。

Now when i click on submit button then my server side code event is fired but my validation pop up doenst appears.

我已经甚至把在web.config中这一行:

I have even put this line in web.config:

  <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"></add>

但是,这仍然没有工作从Response.Redirect的或windows.location.href然后我的验证去除查询字符串弹出成功出现,这是工作的罚款。

But this is still not working as removing query string from response.redirect or from windows.location.href then my validation pop up successfully appears and it is working fine.

任何人可以帮助我吗?

推荐答案

如果像你说的, window.Page_Validators [I] .isvalid 的typeof(window.Page_Validators [I] .errormessage)真正,那么我们就必须进入'如果'的条件。计数器必须设置为1,然后必须进入'如果'以后。

If, as you say, window.Page_Validators[i].isvalid is false and typeof (window.Page_Validators[i].errormessage) is true, then we must go into the 'if' condition. The counter must be set to 1, and then must go into the 'if' later on.

我已经改变了检查一点点,增加了控制台日志记录,以帮助你。如果有人不知道,你可以通过点击 F12 在浏览器中,然后单击控制台查看这些消息。

I've changed the checks a little bit and have added the console logging to help you. In case anyone doesn't know, you can view these messages by hitting F12 in the browser and clicking "Console".

function checkvalidation() {
        window.Page_ClientValidate('validate');
        var counter= 0;
        var val= '';
        for (var i = 0; i < window.Page_Validators.length; i++) {
            if ( (window.Page_Validators[i].isvalid === false) && typeof (window.Page_Validators[i].errormessage) == "string") {
                console.log("Inside the if condition");
                console.log(window.Page_Validators[i]);
                counter = 1;
                val+= '-  ' + window.Page_Validators[i].errormessage + '<br>';
            }
        }
        if (counter === 1) {
          //My validation pop up to display validations alert because this counter value remains 0 so this part is not executed.
        }
    }

这篇关于添加查询字符串时验证不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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