This is a migrated thread and some comments may be shown as answers.

close window with CustomValidator up

5 Answers 95 Views
Window
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 13 Dec 2012, 10:18 AM
hi guys,
i'm loading a web page into radwindow....the my code to close the radwindow is:
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow;
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}
function Close() {
    GetRadWindow().close();
}
 
and i call it form code behind with this code:

Protected Sub Imgbtnclose_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles Imgbtnclose.Click
    Me.ClientScript.RegisterStartupScript(Me.GetType, "", "Close();", True)
End Sub

now in this page there's a radupload object and a custom validator objcect that i used to see the extension error and the code is:

<asp:CustomValidator ID="CustomValidator1" runat="server"
    ClientValidationFunction="validateRadUpload"
    ErrorMessage="Extension error" Font-Bold="True" ForeColor="Red"
    OnServerValidate="CustomValidator1_ServerValidate"
    ValidationGroup="carica"></asp:CustomValidator>
 
    function validateRadUpload(source, e) {
        e.IsValid = false;
        var upload = $find("<%= RadUpload1.ClientID %>");
        var inputs = upload.getFileInputs();
        for (var i = 0; i < inputs.length; i++) {
            //check for empty string or invalid extension    
            if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) {
                e.IsValid = true;
                break;
            }
        }
    }

all this code is ok, but when click on close button for close the radwindow, start the custom validator and start the message error. I would that when click on close button, don't start the validator code but start the code close the radwindow.

Why can i do it?

Thanks












5 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 13 Dec 2012, 02:33 PM
Hello Fabio,

When a postback should be initiated by a button it can be prevented by validators that are either in the same ValidationGroup, or that have no ValidationGroup set and your button has no ValidationGroup set as well. If either of this is your case then you have the expected behavior.

If possible, you can avoid the postbnack and execute the Close() function in the client-side click of the button. If you need the postback to execute some code I advise that you first initiate the postback properly, as this is not related to the RadControls but to the general way ASP validation works and depends on  your scenario. Once you hit the server handler things should work fine. Nevertheless, if you cannot register the script properly this help article can be helpful.

In case you are referring to the RadWindow's own close button (the [X] at the top right corner) - it, by default, would not initiate the validation, as it does not access the page inside. If this happens the most likely reason for it is some custom handler (OnClientBeforeClose for example) that executes some logic and cancels the closing of the control. What I can advise is that you review your code for such handlers. Note that it does not execute this same code, but it handles the closing internally.


Kind regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Fabio Cirillo
Top achievements
Rank 1
answered on 13 Dec 2012, 02:55 PM
Hi,

i load the radwindows with this code:
<telerik:RadWindow ID="RadWindowLoadprofile" runat="server"
ShowContentDuringLoad="false" Width="393px"
Height="300px" Title="Caricamento immagine profilo" Behaviors="None"
MaxHeight="300px" MaxWidth="400px" Modal="True" Behavior="None"
Font-Names="Verdana" Font-Size="Small" IconUrl="/image/iconlogo.png"
ToolTip="Caricamento immagine profilo" OnClientClose="RefreshHome"
VisibleStatusbar="False" NavigateUrl="UploadImgProfile.aspx"
Skin="Simple">
</telerik:RadWindow>

and the function RefreshHome is:

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
         <script type="text/javascript">
             // ritorna valore dell'immagine del profilo
             function RefreshHome(sender, eventArgs) {
              var strimage = eventArgs.get_argument();
              var img = document.getElementById('<%= ImgProfile.ClientID %>');
              img.src = strimage;
              return false;
             }
 </script>
</telerik:RadCodeBlock>

now when i've completed the upload and i mus to close the radwindows and update the image on the primary page, i call this code:

Protected Sub Imgbtnesci_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles Imgbtnesci.Click
    ClientScript.RegisterStartupScript(Me.GetType, "closeWindow", "<script type='text/javascript'>GetRadWindow().close('" & ViewState("DirImage") & "')</script>")
End Sub

and aps code is:

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
     <script type="text/javascript">
             function GetRadWindow() {
                 var oWindow = null;
                 if (window.radWindow) oWindow = window.radWindow;
                 else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                 return oWindow;
             }
             function Close() {
                 GetRadWindow().close();
             }
         </script>
 </telerik:RadCodeBlock>

the imagebutton has the property ValidationGroup:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:ImageButton ID="Imgbtnesci" runat="server" ImageUrl="~/Image/esci1.png"
            ValidationGroup="close" />
    </ContentTemplate>
</asp:UpdatePanel>

now please help me to close the radwindow without to use the deafult button "X" but tu use the imagebutton

the problem is in the handling of the postback in ajaxpanel I need to manage the loading during upload
this:
                                     function conditionalPostback(sender, args) {
                                             if(args.get_eventTarget() == "<%= imgbtncarica.UniqueID %>")
                                                 args.set_enableAjax(false);
                                         }
 
             <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" height="230px"
             width="300px" HorizontalAlign="NotSet"
                ClientEvents-OnRequestStart="conditionalPostback">
.......






0
Marin Bratanov
Telerik team
answered on 14 Dec 2012, 01:32 PM
Hello Fabio,

Your Imgbtnesci button is inside an update panel, so the script regitration has to go through the ScriptManager as I advised in my previous reply: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html.

You can find attached a sample I build on top of your snippets that works with me. You can use that as base to get it working on your end as well and to compare for differences. Note the changes I have made - the Close() function now takes an argument, as it makes creating the server script shorter and thus easier. Also the properties I have marked with an underscore are not implemented in the control and will not have effect (with the exception of Behavior - it is simply obsolete and you should use Behaviors).


Regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Fabio Cirillo
Top achievements
Rank 1
answered on 14 Dec 2012, 02:38 PM
hello,
everything works, feel I wanted to ask two other questions:

1) every time I want to make a working javascript from code behind I always ultizzare the RadScriptManager.RegisterStartupScript or ScriptManager.RegisterStartupScript?

2) in the code that I've changed that:
ScriptManager.RegisterStartupScript (Page, Me.Page.GetType (), "CloseWindow", "Close ('" & ViewState ("DirImage") & "')", True)

I understood that the object image on the main page is loaded already, open the radwindow to make another upload but close immediately without any upload, with the above code, the object image and removes his image remains empty.
How can I pass through JavaScript or other code the actual value of the imageurl radwindow so that if I close without making any upload, it always loads the previous image
0
Marin Bratanov
Telerik team
answered on 17 Dec 2012, 02:59 PM
Hi Fabio,

Straight to your points:

1) This is the same method. RadScriptManager inherits and extends the standard ScriptManager and this method is one of the inherited. We add our own CDN, combination of scripts, etc. Using ScriptManager.RegisterStartupScript() would be safer in case you work on a project that does not reference Telerik.Web.UI.

2) if you do not pass an argument at all (or directly use the [x] button in the RadWindow titlebar) the eventArgs.get_argument() method will return null, so you can check for that and only update the main page if new data arrives. You can see such a check here.


Regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Window
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Fabio Cirillo
Top achievements
Rank 1
Share this question
or