Simple tuto about how to use radconfirm() in radbutton

7 posts, 1 answers
  1. Pharsat
    Pharsat avatar
    11 posts
    Member since:
    Oct 2011

    Posted 18 Nov 2011 Link to this post

    Hi. it is my primer tuto post.
    Topic: how use RadConfirm() function in a button (or another control with similar ClientEvents) without make a full postback (just it is different to use confirm javascript function).

    scenario:
    Asp.net framework 4, RadControls for asp.net 2011 Q2, c# development

    Steps.
    1.    Add this controls to you aspx file.
        RadScriptManager
        RadAjaxManager
        RadWindowManager
        RadButton
        Another controls that satisfy your needs.
    2.    Set ajax manager to your fits, for example set radbutton as fire control and a image control as updated control
    3.    Set onClientClicked event of your radbutton as: 'CheckItem'
    4.    Set CommandName argument as 'btnShowImage' (or of you preference, this must identify unique control)
    <telerik:RadButton ID="btnShowImage" runat="server" Text="Show Image"
    OnClick="btnShowImage_Click" CommandName="btnShowImage"
    onclientclicked="CheckItem">
    </telerik:RadButton>

    5.    include next javascript code in your aspx file.
    function CheckItem(sender, e) {
        if (sender._commandName == "btnShowImage") {
            RadConfirm("¿are sure?", btnShowImageResume, 330, 100, null, "Confirm.");
            sender.set_autoPostBack(false);
        }
        else {
            sender.set_autoPostBack(true);
        }
    }
     
    function btnShowImageResume(arg) {
        if (arg) {
            __doPostBack("btnShowImage", "onclick");
        }
    }

    Explain: btnShowImage is a button which when pressed displays the image in an image field (or your explicit need). this button must have some postback event for this example 'onclick' event (behind code). when user clicks on the radbutton fires client side event 'CheckItem' if command name parameter match with button then function call RadConfirm method: "RadConfirm(confirm message, javascript function that be executed after user take a decision, width, height, objet reference, message tittle);"
    After, javascript cancel objet postback (preventing that compiler continues with onclick event code.) else continues with postback.
    When user takes a decision RadConfirm call resume function in this example:'btnShowImageResume' function, this function validate if arg parameter (result) is true then executes onclick event of the control else does not do nothing (you can execute another event if you want). when we call to _dopostback javascript function, RadAjaxManager evalues situation and execute its.

    I hope they will be of great help.
  2. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 19 Nov 2011 Link to this post

    Cristian,

    Please excuse me if I've misunderstood your question, but I think that you are trying to prevent a postback if the button's CommandName == "btnShowImage" and if the user clicks OK on confirm.

    If that is the case, then you might want to try this ...
    <telerik:RadButton ID="btnShowImage" runat="server"
       Text="Show Image"
       AutoPostBack="true"
       OnClick="btnShowImage_Click"
      CommandName="btnShowImage"
      OnClientClicking="CheckItem">
    </telerik:RadButton>

    function CheckItem(sender, e)
    {
      if(e.get_commandName() == "btnShowImage")
      {
        radconfirm("¿are sure?", function (arg) { if(!arg) { e.set_cancel(true); }}, 330, 100, null"Confirm."); 
      }
    }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Pharsat
    Pharsat avatar
    11 posts
    Member since:
    Oct 2011

    Posted 23 Nov 2011 Link to this post

    Hi stuart.
    mm this is not question, but i explain you what happen when you make this.
    i'am using radbutton, the button have OnClick="btnSalir_Click" (server-side) CommandName="btnSalir" (client-side) events, using your code if i press this button efectly show radconfirm but continues inmediatly whit server side code (without wait for user response).

    chek this instruction:
    RadConfirm("¿are sure?", btnShowImageResume, 330, 100, null, "Confirm.");

    sender.set_autoPostBack(false);
    inmediatly after radconfirm i cancel postback whit the purpose of stop server side code execution.

    after a user response then i do postback wht the event requested in this case, onclik.

    this way was witch one that i founded for stop and reactivate code execution.

    Have I
    understood?.

    if you have  another way more easy or another solution thanks for reply :)
  5. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    3602 posts

    Posted 23 Nov 2011 Link to this post

    Hello guys,

    The confirmation you are trying to achieve is already shown in two online demos - one from the RadButton section and one from the RadWindow section:
    Confirm postback from RadButton which shows several approaches (with different complexity and look) and utilizes the RadButton's API better
    Confirm postback via RadConfirm shows a more generic approach on things and integration with the standard ASP controls.



    Best wishes,
    Marin
    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
  6. Pharsat
    Pharsat avatar
    11 posts
    Member since:
    Oct 2011

    Posted 23 Nov 2011 Link to this post

    jeje i dont know but i did'nt catch it.
    when they put that link?.
    i were thinking that it was my first contibution for community.
    thanks!
  7. MTC
    MTC avatar
    26 posts
    Member since:
    Jan 2013

    Posted 13 Feb 2013 Link to this post

    Hi
    I have a simple requirement to create a record in Data Base. for this i have some fields on my webpage after filling that fields user can create a record.
    for this i am using RadAjaxPanel,RadScriptBlock,Rad Button,RadAjaxManager and RadAjaxLoadingPanel.
    the flow for creating r record would be:
    -> On button click first i want to call a JavaScript for validation( not asp validation) it returns true for successful validation else false..
    ->if it is true loading panel should appear on the screen and server side code should run.
    -> if it is false then loading panel should not appear JavaScript error message should display..

    Please help....
  8. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 14 Feb 2013 Link to this post

    Hello Shweta,

    I have provided information about your scenario in this forum, which you used for reporting the same problem. Please follow the listed steps for implementing the desired functionality.

    I would suggest using a single forum thread when reporting a problem in the future. This way all the information on the case will be in one place which will allow us to resolve the issue faster. Let us continue our discussion in the thread I linked above.

    Greetings,
    Slav
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017