Block the execution thread with radconfirm

50 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 29 Nov 2006 Link to this post

    Requirements

    r.a.d.window version

    1.x

    .NET version

    1.1, 2.0

    Visual Studio version

    2003, 2005

    programming language

    C#

    browser support

    all browsers supported by r.a.d.window

    PROJECT DESCRIPTION

    The project here is based on the Confirm Postback Dialog forum thread. It shows a possible workaround which will allow the radconfirm window to simulate the blocking of the execution thread while waiting for user's confirmation.

    TIP: Examine the Confirm Dialog Integration live demo to see an example with the current codebase (UI for ASP.NET AJAX). Its description explains the scenario, its possibilities and limitations in detail.

    The main issue with the radconfirm dialog is that one cannot block the execution of the thread by Javascript. That is why we provided a workaround that helps in some of the common scenarios. 

    The workaround does not work in all cases - it will work only for elements that have a click method. In the workaround we support links and buttons under IE and Firefox. In fact the links do not have a click method under Firefox,  and that is why in the javascript we are using a hack to achieve this behavior.

    The javascript is provided as is and you can modify and extend it further to fit other cases.

    To run the code, extract the zip file in a convenient location and copy the appropriate files in your .Net 1.1 or .Net 2.0 project.

  2. Vic
    Vic avatar
    20 posts
    Member since:
    Jun 2004

    Posted 09 Feb 2007 Link to this post

    I have the following situation:
    I have field validations that should come up when clicking on the button. But instead, it jumps the validation and goes to the confirmation window. I need the following: Show me my "Validation Summary" first and if every validation is good than and only then show the confirmation window!. What do I need to change?
  3. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 12 Feb 2007 Link to this post

    Hi Sterling,

    From your explanation it seems that you expect the "blocking" confirm to actually block the browser thread inside your javasript code. This is not possible.

    The posted project demonstrates a simulation of blocking confirm that "looks" so, only if invoked directly as the only code executing in the onclick event of links, buttons, images etc.

    If you need to simulate blocking radconfirm within code, you should break your code in two and put the "post-confirmation" logic in a separate callback function as demonstrated in our online example:
    http://www.telerik.com/demos/aspnet/Window/Examples/BrowserDialogBoxes/DefaultCS.aspx



    Best regards,
    Tervel
    the telerik team
  4. Vic
    Vic avatar
    20 posts
    Member since:
    Jun 2004

    Posted 12 Feb 2007 Link to this post

    The link is taking me to a newspaper in a language I do not understand!
    Did you give me the incorrect link???? Thanks!
  5. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 13 Feb 2007 Link to this post

    Hello Sterling,

    I apologize for the mistake. The actual link points to our Alert, Prompt, Confirm demo:
    http://www.telerik.com/demos/aspnet/Window/Examples/BrowserDialogBoxes/DefaultCS.aspx


    I have also changed the link in the previous reply.


    All the best,
    Georgi Tunev
    the telerik team
  6. Lolo
    Lolo avatar
    17 posts
    Member since:
    Mar 2007

    Posted 07 Mar 2007 Link to this post

    Thank for the example it was very useful and it worked successfully.
    But what if I Want to use it with a GridView button column in the Row Command. I tried it but It does not work. Pressing Yes in the Rad Confirm does not apply any thing.
     
  7. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 08 Mar 2007 Link to this post

    Hi Latifa,

    You can use the attached sample as a base and extend it to fit your scenario.

    If you have other questions, please use the support ticketing system.



    Best wishes,
    Georgi Tunev
    the telerik team
  8. David Sitton
    David Sitton avatar
    52 posts
    Member since:
    Nov 2004

    Posted 08 Oct 2007 Link to this post

    Hi,
    this solution worked nicely, although I struggled to get the "are you sure?" message localised. I got the "yes" and "no" buttons working, but the "are you sure?" message is specified in the function, so I think its overwriting the supporting .xml file.

    Can anyone help?
  9. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 08 Oct 2007 Link to this post

    Hello David,

    The radconfirm() message can be set only in the radconfirm() function. The localization string in the XML file is not used and will be removed in one of the following updates.




    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. David Sitton
    David Sitton avatar
    52 posts
    Member since:
    Nov 2004

    Posted 09 Oct 2007 Link to this post

    Georgi,
    have you got any suggestions for setting a string from an xml file. I'm generally a server-side programmer and am inexperienced with clietn side programming. Could i just set the value of a literal from server side and use the localised string from there?
  11. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 09 Oct 2007 Link to this post

    Hi David,

    In the last example's code, the calling of the radconfirm is built on the server:

    button.OnClientClick = string.Format("radconfirm('Are you sure you want to delete: {0}', event, 400, 200, '', 'Delete Record {1}');",

    you can create and use any string that you want there - just add it in string.Format() and it will be outputted on the client.

    If you experience problems with this approach, please implement the desired logic by using not radconfirm() but a standard browser's confirmation dialog (window.confirm()). Once your solution is working as desired, send us the project and we will rework it for you so it uses radconfirm().




    Best wishes,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  12. David Sitton
    David Sitton avatar
    52 posts
    Member since:
    Nov 2004

    Posted 10 Oct 2007 Link to this post

    Georgi,
    in the RadConfirmBlockThread.zip example; the server side call is simply:
    Response.Write("Postback from asp:Button initiated");

    all the rest is javascript. The moment of calling in javascript is embedded in a button and looks like:

    <cc2:LocalizedButton ID="locSave" runat="server" CssClass="resetBtn" Key="inlineSave"OnClick="locEdit_Click" OnClientClick="return radconfirm('Are you sure?', event, 300, 150,'',' ');" />

    ..have you any advice for 'injecting' a localised string into the title, which is specified as 'Are you sure?' in the above example?
  13. GT
    GT avatar
    52 posts
    Member since:
    May 2006

    Posted 11 Oct 2007 Link to this post

    You can try the following:
    1.  create a property on the server that will return the string that you want
    2. put the javascript code from the OnClientClick property in a separate function and get the property as string there

    e.g. in your page

    function confirmation()
    {
    radconfirm(
    '<%= questiontext %>', event, 400, 200,'','Custom title');
    return false;
    }
    </script>
    <asp:Button ID="btnDelete" runat="Server" OnClientClick="return confirmation()".....

    and in the codebehind:

    public string questiontext
    {
        get 
            {
                return "sure?"; //create your string here
            }
    }

    worked for me :)

  14. art.clark
    art.clark avatar
    10 posts
    Member since:
    Sep 2006

    Posted 11 Oct 2007 Link to this post

    When I wanted to / menuitem / button in an ajax enabled page, I had a problem with FireFox. Obviously, I wanted to keep as much aditional code in the dialog than in the parent page to keep the ajax requests small. So, instead of using a callback function, I acquired the sending link reference, and called it's href from within the iframe. Because FF has each IFRAME in a separate thread, I had to use setTimeout to eval that link. After I set setTimeout, I immediately dismiss the dialog, which would have aborted the original eval(sendinglink.href) call. This was my solution. 
    Note: the menuitem which required showing a dialog did so using a syntax similar to the following:
    <a href="javascript:AN..." onclick="showModalDialog(this,'customConfirmDialog.asx');return false;" >...</a>.

    I will attempt to package a sample with this functionality sometime, but for those struggling with unnecessary callbacks, this is for you!

    var FF=true;//for testing purposes
    var NS=true;//for testing purposes
    function DoEval(v){
     try{
      if(FF||NS){
       /* Using setTimeout to execute the menuitem's href because the FireFox Iframe's thread ends before execution of the link's href begins-thus aborting */
       setTimeout('eval("'+v.replace(/%20/g,'').replace(/"/g,'\'')+'");',2000);
      }else if(IE && !FF){
       eval(v);
      }else{
       /* Other browsers: OP */
       eval(v);
      }
     }catch(e){}
    };
  15. Rycho
    Rycho avatar
    162 posts
    Member since:
    Feb 2007

    Posted 03 Mar 2008 Link to this post

    Hi,

    Is there any chance that my scenario will keep javascript on hold till closing radconfirm? Below in code snippet I'm trying to drag and drop treeview node. I'd like to give a chance of canceling to the user but with no avail.

        function BeforeNodeDrop(sourceNode, destNode, events, dropPosition)
        {
            if (destNode != null)
                {
                    if ((sourceNode.Parent != destNode) && (destNode.Parent != sourceNode))
                    {
                        var ParentNode=destNode.Parent;

                        while (ParentNode != null)
                        {
                            if (ParentNode==sourceNode)
                            {
                                return false;
                            }
                           
                            ParentNode=ParentNode.Parent;
                        }
                        return radconfirm("Are you sure?",null, 400, 150);
                    }
                }
                return false;
        } 

    Rycho
  16. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 04 Mar 2008 Link to this post

    Hi Rycho,

    I am afraid it is not possible to use radconfirm in this scenario - as noted in this thread, radconfirm() cannot block the execution thread and the hack will not work in such environment. In your case I recommend to use the standard, browser's confirm dialog.



    Best wishes,
    Georgi Tunev
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  17. Michael
    Michael avatar
    7 posts
    Member since:
    Feb 2008

    Posted 28 Aug 2008 Link to this post

    Hi,

        I'm currently using RadControls for Asp.Net Q1 2008.

    I would like to know why you clear the onclient property in your hack.

    e.g.     callerObj["onclick"] = "";

    Because I experiment some problems to implement your solution. In fact, I try to have a blocking confirm fired by a input button click. But it doesn't work until I remove the above line of code.

    But once I comment this line it works fine. So, is it necessary ? If yes why ?

    In addition, I would like to know what is the difference between these to lines:
    • oldConfirm(text, callBackFn, 300, 100, null, null);      
    • oldConfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
    So, how the parameter callerObj changes the behavior ?

    Best regards,
    Mike
  18. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 29 Aug 2008 Link to this post

    Hello Michael,

    Can you please post here your code so we can check it? In general this parameter should not affect your code.
    As for the second question, in the second function you do not set callerObj and title for the radconfirm() dialog.


    Greetings,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  19. Michael
    Michael avatar
    7 posts
    Member since:
    Feb 2008

    Posted 29 Aug 2008 Link to this post

    Hello,

             I don't have time to package some code, so could you simply answer to my questions ?

    1- Why you clear the onclient property in your hack ? (the problem isn't my code, I isolate my test with a simple input button)

    e.g.   callerObj["onclick"] = "";
             if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz  
            else if (callerObj.tagName == "A") //We assume it is a link button!  
             {                                                         
                  try 
                  {  
                        eval(callerObj.href)  
                   }  
                   catch(e){}  
              }



    2-    *  oldConfirm(text, callBackFn, 300, 100, null, null);      
            * oldConfirm(text, callBackFn, oWidth, oHeight, [callerObj], oTitle);

    What is the purpose of the parameter within brackets ? --> callerObj

    Ps: I don't want you understand my environment, I just want an answer.

    Thanks,
    Mike
  20. Tervel
    Admin
    Tervel avatar
    1337 posts

    Posted 01 Sep 2008 Link to this post

    Hello Michael,

    This code has been originally developed more than two years ago. Looking at it now it is not absolutely clear why the onclick attribute is cleared. As far as we are able to understand, you claim that it all worked fine in your scenario after removing the line. If that is so, our suggestion is to go ahead and use your modified code.

    Please note, that the code was developed to work for link tags (A tags), as well as buttons (INPUT tags). Different browsers have different implementations - for example, in IE both buttons and links have click() method. In FireFox only buttons have it. In some browsers calling click() causes the onclick eventhandler attached to an element to fire and execute as well. In other browser - it does not happen.

    To wrap it up, when the code was developed a long time ago, probably while testing a particular browser it was discovered that an unpleasant side effect occurs that mandated the need to add this line of code. Since then many browser updates have happened, and browser behavior does change with every new version. It could be the case that this code is not needed now (when we have IE7 and FF3), but could have been needed for FF1, for example.

    I hope this answer provides you with the explanation you have been seeking. Feel free to modify the code as much as you like to fit your particular needs. This code is provided "as is", and does not provide a universal solution in all scenarios (if it did it would be integrated into the actual RadWindow product itself).

    All the best,
    Tervel
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  21. Ponna
    Ponna avatar
    3 posts
    Member since:
    Sep 2008

    Posted 19 Sep 2008 Link to this post

    Hi,

    I have a requirement to show confirmation after a server side check when a button in grid is clicked. I cannot attach any control to radconfirm. ie I cannot do something like this below.

    btn.attributes.add("onclick","radconfirm('sure?',event,300,200,'','confirm')");

    because server side check needs to be done first.

    I am invoking like

    string

    scriptstr = "radconfirm('Sure to buy this?', event,330, 210,'','');";

     

    ScriptManager.RegisterStartupScript(radGrid,Page.GetType(), "TEST", scriptstr.ToString(),true)

    When I debug the script, the event argument is null.

    Please help how to set the valid value for event.

    Please I cannot use the Callbackfunction instead of event argument, since the page is using new radconfirm feature for many other buttons in the radgrid.

    Since no proper event argument is set, the new confirm script block fails and hence no radconfirm is popped up.

    Thanks

     

  22. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 23 Sep 2008 Link to this post

    Hello Ponna,

    radconfirm accepts a callback function, as a second argument, that is mandatory for its proper operation. If you want to use the original radconfirm() dialog on a page that is using the code provided in the code library, you can do that by using oldConfirm() - as you can see in the JavaScript code (var oldConfirm = radconfirm;) this is possible.



    Sincerely yours,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  23. Xcalibur
    Xcalibur avatar
    11 posts
    Member since:
    Jul 2007

    Posted 24 Sep 2008 Link to this post

    Here is an alternative for those, like me, that have had a lot of problems with getting this solution to work properly.  In my opinion it is much simpler and more elegant and should work on all browsers.  My situation involved showing a confirmation dialog and running the serverside Click event code only when the user clicked YES:

    1) Define a button with the click events set like this:

    OnClick="button_Click"
    OnClientClick='radconfirm("Are you sure?", ClientCallback); return false;'

    This will cause the 'onclick' attribute of the button to be rendered like so:

    onclick="radconfirm("Are you sure?", ClientCallback); return false;__doPostBack('ctl00$...$button','')" 

    which will return and stop the postback happening automatically when the button is clicked.  Of course you can call a JS function instead of radconfirm() directly if you need to.

    2) Define the callback function:

    function ClientCallback(arg)
    {
        if (arg)
        {
            __doPostBack('<%= button.UniqueID %>''');
        }
    }

    Now when the confirm dialog returns, it will fire the callback and if the result was true (YES clicked) then the function will manually postback the page using the correct ID of the initiating button

    WALLAH the server-side Click event code will be run at this point!

    Hope that helps someone.
  24. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 24 Sep 2008 Link to this post

    Hello Xcalibur,

    Thank you for sharing your code with us. Actually, the code that is posted in that Code Library is doing pretty much the same, so whether one will use the CL's code or the approach that you shared, depends entirely on the developer and the exact case.



    Regards,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  25. armando
    armando avatar
    4 posts
    Member since:
    Sep 2008

    Posted 15 Oct 2008 Link to this post

    Hi, someone can help me? I need to call a radconfirm from code behind, someone  will have an example?
    Thanks.
    This is my case:

       if trafic.text = "Tranfer" then
          resp= radconfirm("Are you want to Save?"
          if resp  then
              save()
          end if
       end if
  26. Suresh Balan
    Suresh Balan avatar
    5 posts
    Member since:
    May 2008

    Posted 27 Nov 2008 Link to this post

    hello,
    I am trying to attach a radconfirm to one button of a radtoolbar by using the sample code. The Cancel button is work but the OK button is not working.( looks like the callerObj.click(); not work ). I want to know why.

    Thanks

     

     

  27. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 28 Nov 2008 Link to this post

    Hello guys,

    Straight to your questions:

    1. Armando, you can find how to call a radalert from code-behind in different scenarios in this KB article. To call radconfirm from the server, you should use the same logic but to replace the radalert with radconfirm message. The radconfir,'s callback function can be declared in the aspx or also outputted from the server.
    2. Suresh, the provided information is not enogh to locate the problem. Would you please prepare a sample project, open a new support ticket and send it to us a detailed explanation of the issue and reproduction instructions?

    Regards,
    Svetlina
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  28. Nicolas Fahr
    Nicolas Fahr avatar
    13 posts
    Member since:
    Dec 2008

    Posted 09 Feb 2009 Link to this post

    In this Version RadControls for ASP.NET AJAX  2008.3 1314  Jan 14, 2009 
    the Release Notes states: "Made the ClientCallBackFunction obsolete "
    The workaround does not work anymore! Any suggestions?
  29. Georgi Tunev
    Admin
    Georgi Tunev avatar
    7207 posts

    Posted 09 Feb 2009 Link to this post

    Hello Nicolas,
    Only the ClientCallBackFunction for RadWindow is obsolete - instead OnClientClose should be used. radconfirm and radprompt however are still using callback functions and the solution is working as expected.

    If you experience any problems, please open a support ticket and send us a small sample project where they can be reproduced. We will check it right away.


    All the best,
    Georgi Tunev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  30. Buča
    Buča avatar
    3 posts
    Member since:
    Mar 2009

    Posted 25 Mar 2009 Link to this post

    Hello!
      I have a problem surrounding RadConfirm dialog and don't know how to solve it.
      The problem is sometimes (don't know in which case - that's part of the problem) when i click the button that returns true (in my case "Da") in the dialog i get the "Unexpected call to method or properly access" error. I can't figure out why this happens but it happens in the "_45.focus();" line of this code:
    ,_getStandardPopup:function(_3e,_3f,_40){ 
    var _41=this._createWindow(_3e+this._getUniqueId(),false); 
    _41.set_destroyOnClose(true); 
    _41.set_modal(true); 
    var div=document.getElementById(this.get_id()+"_"+_3e.toLowerCase()+"template"); 
    var _43=this._stringFormat(div.innerHTML,_41.get_id(),_3f,_40?_40:""); 
    _43=this._replaceLocalization(_43,Telerik.Web.UI.RadWindowUtils.Localization); 
    var _44=document.createElement("DIV"); 
    _44.innerHTML=_43; 
    _41.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close); 
    _41.set_visibleStatusbar(false); 
    _41.set_contentElement(_44); 
    var _45=_41.get_contentElement().getElementsByTagName("INPUT")[0]; 
    if(!_45){ 
    _45=_41.get_contentElement().getElementsByTagName("A")[0]; 
    if(_45&&_45.focus){ 
    window.setTimeout(function(){ 
    _45.focus(); <<--HERE!
    },0); 
    return _41; 

    Now, in normal exectution of a dialog this code runs before the dialog is open and it does not go in the "if(_45&&_45.focus){" part. But somethimes after the OK button is clicked it goes directly inside the if and throws an error. The declaration for window.setTimeout i did not found in the code.

    The code i am using:

      I am using slightly changed version of the window.RadConfirm function
    //Replace old radconfirm with a changed version. 
    var oldRadConfirm = window.radconfirm; 
    //window.radconfirm = function(text, mozEvent) 
    //We will change the radconfirm function so it takes all the original radconfirm attributes 
    window.radconfirm = function(text, mozEvent, oWidth, oHeight, callerObj, oTitle) { 
        var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually    
        //Cancel the event    
        ev.cancelBubble = true
        ev.returnValue = false
        if (ev.stopPropagation) ev.stopPropagation(); 
        if (ev.preventDefault) ev.preventDefault(); 
     
        //Determine who is the caller    
        var callerObj = ev.srcElement ? ev.srcElement : ev.target; 
     
        //Call the original radconfirm and pass it all necessary parameters    
        if (callerObj) { 
            //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.    
            var callBackFn = function(arg) { 
                if (arg) { 
                    try { 
                        if (callerObj.href != null) { 
                            eval(callerObj.href); 
                        } 
                        else { 
                            __doPostBack(callerObj.name, ''); 
                        } 
     
                    } 
                    catch (e) {} 
                
                } 
            } 
            //TELERIK 
            //oldConfirm(text, callBackFn, 300, 100, null, null);        
            //We will need to modify the oldconfirm as well 
            oldRadConfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle); 
        } 
        return false
     
    My RadWindowManager in aspx is defined like this:
    <eaf:IxRadWindowManager ID="ioIxRadWindowManager" runat="server" ReloadOnShow="True" ShowContentDuringLoad="False"
        <ConfirmTemplate> 
          <div class="windowpopup radconfirm">    
            <div class="dialogtext"> {1} </div>       
          </div> 
          <center> 
            <div> 
              <center> 
              <div style="float:left; width:100%;"
                <eaf:IxButton ID="ioIxButtonYes" runat="server" Text="Da" OnClientClick="$find('{0}').callBack(true);" />&nbsp;&nbsp;&nbsp; 
                <eaf:IxButton ID="ioIxButtonNo" runat="server" Text="Ne" OnClientClick="$find('{0}').close(false);" /> 
              </div> 
              </center> 
            </div> 
          </center> 
        </ConfirmTemplate> 
      </eaf:IxRadWindowManager>  

    And the code that calls the dialog box in aspx like this:
    <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="Briši" CommandName="Delete" 
                        ImageUrl="~/images/p16.png" CssClass="eGridButtonDelete" OnClientClick="radconfirm('Zapis bo brisan, želite nadaljevati?', event, 360, 150, null,'Brisanje zapisa'); return false;" /> 

    Help!
    Thank you,
     Gregor
Back to Top