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

Radconfirm with argument passed to callbackfunction?

3 Answers 691 Views
Window
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 24 Mar 2009, 04:07 PM
I have a radgrid with checkboxes for each row and a save button below the grid to save the selections to the database. It only saves page by page, so that if a user clicks the next page and has not saved, I want to pop up a radconfirm alerting the user that he has not saved, and give him a yes/no choice to change pages. The change page function takes an agument of 'next' or 'prev' or 'first' or 'last'. If on page change click I call a function that calls radconfirm, and then the callbackfunction for radconfirm will change the page if clicked yes, the argument for page direction gets sent, but not an argument for the yes or no. How do I get the confirm arguement sent to the call back funtion?

Here is a bit of code: argument is the 'next', 'prev'..... the function cp1 is trying to test if they clicked yes, but arg is null.

  <asp:ImageButton ID="Button1"  runat="server" OnClientClick="changePage1('first'); return false;" 
                        CommandName="Page" CommandArgument="First" ImageUrl="~/Images/first.gif" />    


function changePage1(argument) { 
               radconfirm('You have not saved your choices. If you change pages you will lose your data. Are you sure you want to change?',  
               
                cp1(argument)); 
               
             // tableView1.page(argument); 
          } 
          function cp1(argument,arg) { 
          if(arg){ 
              tableView1.page(argument); 
              } 
          } 

3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 24 Mar 2009, 04:18 PM
Hello Laura,

The callback function of radconfirm and radprompt accepts only one argument and you can only declare the function's name in radconfirm / radprompt's syntax.
In scenarios like yours, I would suggest to put the callback function in the function with which you are calling the radconfirm dialog - this way you will have access to the argument passed in the changePage1 function:

function changePage1(argument)  
{  
    function cp1(arg)  
    {  
        if(arg){  
          tableView1.page(argument);  
          }  
    } 
     
    radconfirm('You have not saved your choices. If you change pages you will lose your data. Are you sure you want to change?', cp1);  
}  
  


Kind regards,
Georgi Tunev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Laura
Top achievements
Rank 1
answered on 24 Mar 2009, 05:07 PM
Thank you for you quick and easy to understand answer. One more question. If the user changes the page number, I have another function to handle that. It is this:

 function Pager_RadNumericTextBox1_ValueChanged(sender, args) { 
              function numericChanger1(arg) { 
                  if (arg) { 
                      tableView1.page(sender.get_value()); 
                  } 
                  else { 
                      sender.set_value(sender._originalValue); 
                  } 
              } 
              radconfirm('You have not saved your choices. If you change pages you will lose the changes you just made. Are you sure you want to change?'
 
                numericChanger1); 
           //   tableView1.page(sender.get_value()); 
          } 
called from this:

  <telerik:RadNumericTextBox ID="Pager_RadNumericTextBox1" Skin="Office2007" Width="25px" 
                                Value='<%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>' 
                                runat="server"
                                <ClientEvents OnValueChanged="Pager_RadNumericTextBox1_ValueChanged" /> 
                                <NumberFormat DecimalDigits="0" /> 
                            </telerik:RadNumericTextBox> 


Now, since I added the new code that you recommended, I also added the line
                  else { 
                      sender.set_value(sender._originalValue); 
                  } 

if the user does not want to change pages so that it goes back to the original value. After I added that, it requires the user to click the No button on the radconfirm window twice to get back. Why is that?

Thanks

0
Georgi Tunev
Telerik team
answered on 26 Mar 2009, 01:57 PM
Hi Laura,

This behavior is expected - when you use set_value(), the OnValueChanged event fires again. In scenario like this, I suggest to use a simple flag that will help you determine in your logic whether there is need for radconfirm or not in OnValueChanged.
e.g.

 var confirmed = null
 
 function Pager_RadNumericTextBox1_ValueChanged(sender, args) {  
 
      function numericChanger1(arg) {  
      //null the flag to ensure that if the valueChanged function is called again, a confirm will popup  
          confirmed = null
           
          if (arg) {  
              alert("value changed"); 
          }  
          else {  
            //set the flag 
            confirmed = true
             
            sender.set_value(sender._originalValue); 
 
          }  
      }  
 
     //check if the user has already confirmed his choice 
      if(!confirmed) 
      { 
        radconfirm('You have not saved your choices. If you change pages you will lose the changes you just made. Are you sure you want to change?', numericChanger1);  
      } 
      else 
      { 
        confirmed = null
      } 
  }  
 


<telerik:RadNumericTextBox ID="Pager_RadNumericTextBox1" Skin="Office2007" Width="25px" 
    Value='20' runat="server"
    <ClientEvents OnValueChanged="Pager_RadNumericTextBox1_ValueChanged" /> 
    <NumberFormat DecimalDigits="0" /> 
</telerik:RadNumericTextBox> 
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"
</telerik:RadWindowManager> 


I hope this helps.

All the best,
Georgi Tunev
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Window
Asked by
Laura
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Laura
Top achievements
Rank 1
Share this question
or