开发者

Telerik RadAjaxManager and ASP.net Validators

I'm trying to use a required field validator along with Telerik's RadAjaxManager.

If I'm using a button then there is no problem and a postback does not occur while the field is empty. However, there are some cases where I'm invoking an ajax request manually, and then a validation does not occur and the postback takes place regardless of whether the field is empty or not.

Here is an example with both a button and a manual request:

<script type="text/javascript">
$("#spanSubmit").click(function()
    {
          $find("<%=RadAjaxManager1.ClientID%>").ajaxRequest();
    });
</script>

<asp:TextBox ID="tb1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="req1" runat="server" ControlToValidate="tb1" Text="!!!"></asp:RequiredFieldValidator>

<asp:Button ID="button1" runat="server" onclick="button1_Click" Text="Submit" />
<span id="spanSubmit">Ajax Request</span>
<asp:Label ID="Label1" runat="server"></asp:Label>

<telerik:RadScriptManager ID="ScriptManager1" runat="server"></telerik:RadScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="button1">
                    <UpdatedControls>                
                        <telerik:AjaxUpdatedControl ControlID="Label1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>                
                        <telerik:AjaxUpdatedControl ControlID="Label1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>

When clicking button1 while the textbox is empty - no postback occurs. When clicking the span while the textbox is empty - the postback occurs, and in the server side req1.IsValid is true, unless I manually call Page.Validate().

Is there a simple way to activate the validator when performing an ajax request like that?

(I realize there are ways to call a validator using javascript, like in this example, but since I may have several validators coming from different custom controls, I was hoping for a 开发者_如何学Pythonsimpler way)


A few weeks ago I searched for the same thing and came across this forum post. It was proposed to use Page_ClientValidate() call and then block the page submission explicitly. Have not given it a try yet as my project tasks are put on hold, but appears to be working for the guy who started the thread, hence you may try it out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜