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

Using TextChanged to build a dynamic confirmation prompt

2 Answers 100 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 29 Oct 2012, 04:48 PM
I have a Combox with a list of cities, if a client's city is missing I want them to be able to update the list on the fly.  Everything is working except one aspect.  In AddNewCityTextbox_TextChanged I simply find the textbox and add the Text to the CommandArgument of the radButton which is used to submit.

This all works, Except that the TextChanged only does a Postback when the Client clicks elsewhere.  In my case they wil logically click on Submit, therefore the JavaScript fires before (or seems to) the script is updated.

Is there another wau I can logically get around this?
Public Sub AddNewCityTextbox_TextChanged(sender As Object, e As System.EventArgs)
 
        Dim TextBox = CType(sender, RadTextBox)
        Dim item = CType(TextBox.NamingContainer, RadListViewEditableItem)
 
        Dim AddNewCityTextbox As RadTextBox = DirectCast(item.FindControl("AddNewCityTextbox"), RadTextBox)
 
        Dim SubmitLink As RadButton = DirectCast(item.FindControl("SubmitNewCity"), RadButton)
        SubmitLink.CommandArgument = "Please confirm you wish to add " & AddNewCityTextbox.Text & "?"
 
 
    End Sub
 
<telerik:RadButton ID="SubmitNewCity" runat="server" Text="Submit" style="margin-right:10px;" ValidationGroup="AddCityGroup"
                OnClientClicking="function(button,args){args.set_cancel(!window.confirm(button.get_commandArgument()));}"  >
</telerik:RadButton>

2 Answers, 1 is accepted

Sort by
0
Accepted
Vasil
Telerik team
answered on 01 Nov 2012, 02:31 PM
Hello Tim,

You can use the client side OnValueChanged event of the RadTextBox and to change the RadButton's commandArgument. This way it will not require PosBack to change the confirmation text. Make sure to remove the AutoPostBack of the RadTextBox as well.

Regards,
Vasil
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
Tim
Top achievements
Rank 1
answered on 05 Nov 2012, 04:09 PM
Thank you, I got this working based on your suggestion.  For everyone's benefit, this is how i did it.

<telerik:RadTextBox ID="AddNewCityTextbox" runat="server" Label="Name of City/Town:" LabelCssClass="AddNewCityTextbox" Font-Bold="true" Width="520" style="margin-left:10px;" >
<ClientEvents OnValueChanged="ValueChanged" />
</telerik:RadTextBox>      
<telerik:RadButton ID="SubmitNewCity" runat="server" Text="Submit" style="margin-right:10px;" ValidationGroup="AddCityGroup" OnClientClicking="ClientClicked"  >
</telerik:RadButton>

  function ClientClicked(button, args) {
 
var newValue = button.get_commandArgument();
var msg = 'Please confirm that you wish to add ' + newValue + '?';
args.set_cancel(!window.confirm(msg));
                     
}
 
 
 function ValueChanged(sender, e) {
 
var newValue = e.get_newValue();
var listView = $find('<%= RecipientOrganizationView.ClientID %>');
 
var AddNewCityTextbox = $telerik.findControl(listView.get_element().parentNode, "AddNewCityTextbox");
var SubmitNewCity = $telerik.findControl(listView.get_element().parentNode, "SubmitNewCity");
 
 
 var button = SubmitNewCity;
button = button.set_commandArgument(newValue);
 
}
Tags
General Discussions
Asked by
Tim
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Tim
Top achievements
Rank 1
Share this question
or