This is a migrated thread and some comments may be shown as answers.
Simple tuto about how to use radconfirm() in radbutton
8 Answers 225 Views
This is a migrated thread and some comments may be shown as answers.
Pharsat
Top achievements
Rank 2
Pharsat asked on 19 Nov 2011, 05:09 AM
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.

8 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 19 Nov 2011, 08:28 PM
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."); 
  }
}
0
Pharsat
Top achievements
Rank 2
answered on 23 Nov 2011, 04:26 PM

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 :)
0
Accepted
Marin Bratanov
Telerik team
answered on 23 Nov 2011, 04:50 PM
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
0
Pharsat
Top achievements
Rank 2
answered on 23 Nov 2011, 05:06 PM
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!
0
MTC
Top achievements
Rank 1
answered on 13 Feb 2013, 07:24 AM
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....
0
Slav
Telerik team
answered on 14 Feb 2013, 05:57 PM
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.
0
Anthony
Top achievements
Rank 1
answered on 11 Jun 2019, 01:23 PM

This is an old post however, I would like to add my experience.  I am using a master page and the java script is in the master page.   I could not get this to work and figured out that the issue lies in the button name.  If this is not working, make sure the button name listed in the "_doPostBack"  is correct.   For example, my "btnSubmit" button is referenced as  "ctl00$ContentPlaceHolder1$btnsubmit" on the master page.

 

I was able to determine the button name by doing an alert(button.name) on he execution.

0
Marin Bratanov
Telerik team
answered on 11 Jun 2019, 01:32 PM
Hello Anthony,

That's a very valid comment - to use __doPostBack() you need the name attribute of the element you want to imitate.

That said, we have just created a built-in confirmation dialog for the buttons, and you can see it in action here: https://demos.telerik.com/aspnet-ajax/controls/examples/integration/buttonconfirmdialog/defaultcs.aspx?product=button.


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Pharsat
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Pharsat
Top achievements
Rank 2
Marin Bratanov
Telerik team
MTC
Top achievements
Rank 1
Slav
Telerik team
Anthony
Top achievements
Rank 1
Share this question
or