Showing posts with label confirmbutton. Show all posts
Showing posts with label confirmbutton. Show all posts

Monday, March 26, 2012

ConfirmButtonExtender with Validators ?

Hi -

does anyone know how to make the confirmbutton extender conditionnal on the validation of the page?

For instance, i've got a button with confirm extender that posts information entered in TextBoxes. Some of those textboxes have validators - so the post won't happen if the textboxes aren't correctly filled in (so i don't need an active confirmation in that case). If the boxes are correctly filled in, then i would like the confirmButtonExtender to be active...

Anyway to make that happen?

thanks for the help!

-bash

I believe this would take some additional code in ConfirmButtonBehavior.js. If you happen to implement the feature, we'd love to include it in the Toolkit!

//
// Custom methods
//ADD this bold text to this function and recompile control toolkit tool - this will first validate the page then display the confirmation dialog

_onClick : function(e) {
if (this.get_element() && !this.get_element().disabled) {
// Display confirm dialog and return result to allow cancellation

if(Page_ClientValidate()) {

if (!window.confirm(this._ConfirmTextValue)) {
e.preventDefault();
return false;
}
}
}
},


this is *.js - i have forgot to put rest code - here it is

PART ONE

_onClick :

function(e) {if (this.get_element() && !this.get_element().disabled) {// Display confirm dialog and return result to allow cancellation

if(this._checkValidatorsValue)

{

if(Page_ClientValidate()) {

if (!window.confirm(this._ConfirmTextValue)) {

e.preventDefault();

returnfalse;

}

}

}

else

{

if (!window.confirm(this._ConfirmTextValue)) {

e.preventDefault();

returnfalse;

}

}

}

},

//// Property get/set methods//

get_ConfirmText :

function() {returnthis._ConfirmTextValue;

},

set_ConfirmText :

function(value) {if (this._ConfirmTextValue != value) {this._ConfirmTextValue = value;this.raisePropertyChanged('ConfirmText');

}

},

get_checkValidators :

function() {returnthis._checkValidatorsValue;

},

set_checkValidators :

function(value) {if (this._checkValidatorsValue != value) {this._checkValidatorsValue = value;this.raisePropertyChanged('checkValidators');

}

}

PART TWO - add this to this file *.cs

[

ExtenderControlProperty()]publicbool checkValidators

{

get

{

return GetPropertyBoolValue("checkValidators");

}

set

{

SetPropertyBoolValue(

"checkValidators",value);

}

}

PART THREE

NOW IF YOU WANT TO USE CONFIRM DIALOG WITH VALIDATORS YOU SHOUL SET IN ASPX FILE IN CONFIRMBUTTONEXTANDER PROPERTY CHECKVALIDATORS TO TRUE

IF YOU WANT TO USE CONFIRM DIALOG WITHOUT VALIDATORS (FOR EXAMPLE ON PAGE THERE ARE NOT VALIDATORS) SET THIS PROPERTY TO FALSE


Related to my reply inthis thread, I believe. The code here seems to be a move along the path to add the mentioned submit event support to ConfirmButton.


FYI, I've just fixed this issue:http://www.codeplex.com/WorkItem/View.aspx?ProjectName=AtlasControlToolkit&WorkItemId=8342.

Confirmbutton Question

I put a ConfirmButton extender for a button. This button is a submit button which is put in the last step of Wizard. The wizard has validations.

My problem is the ConfirmButton dialog doesn't pop up before the validation logic kicks in.

Any clue?

Try to set UseSubmitBehaviour property of button

For additional information

Validation controls, which includes theBaseCompareValidator,BaseValidator,CompareValidator,CustomValidator,RangeValidator,RegularExpressionValidator,RequiredFieldValidator, andValidationSummary control are not compatible with UpdatePanel

http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx

Download compatible version of validators from here

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx

ConfirmButton Question

HI,

How to change ConfirmButton ConfirmText using JavaScript?

Thanks

Hi,

Not sure how you are creating your confirm buttons but this may help:

http://forums.asp.net/t/1152598.aspx

Set up your delete button like this:

<asp:ButtonID="btnDelete"runat="server"Text="Delete"OnClick="Delete"OnClientClick="return confirm('Are you sure you want to vaporize this item?')"/>

Hope this helps,
DJH


Actually,

I was talking about AJAX ConfirmButton extender..

Anyway I got other solution for my question.

Thanks

ConfirmButton Problem

Hi all, im new here and also to asp/ajax.. ive got a slight question to ask which may be simple.. im using the confirmbutton extender programatically as shown below

Dim lnkOptionAs New LinkButton lnkOption.Width = 50 lnkOption.Text ="Delete" lnkOption.ID = lblUser.TextAddHandler lnkOption.Click,AddressOf Delete ContentPanel2.Controls.Add(lnkOption)Dim btnConfirmAs New AjaxControlToolkit.ConfirmButtonExtender btnConfirm.TargetControlID = lblUser.Text btnConfirm.ConfirmText ="Are you sure you want to delete ?"

It retrieves a list of users and lists them down on a page using a for loop... now id like each option to have a delete ability as shown in the code above.. however the code doesnt seem to work as i think im missing something out since it doesnt show the text "Are you sure you want to delete ?"

Thanks :)

I don't see any code that adds the btnConfirm to the page...are you doing this?

Jason

ConfirmButton not working

Hi,

I have a page with an update panel and a repeater inside the panel. I have a multi view inside the repeater item template. In that multiview, I have a view with a delete button and a confirm button extender. When you click on the delete button, the confirm alert appears (not always), but at the same time an asyncrhonous postback occurs, the record is deleted by the code behind page and the page is refeshed, but you have not clicked 'OK' nor "Cancel" yet.

Note: Using Beta

Here is the web page:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Templates.aspx.cs" Inherits="Templates" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="sm" runat = "server" />
<asp:ObjectDataSource ID="CategoriesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCategories" TypeName="DataLayer.ProtocolCategory"></asp:ObjectDataSource>
Select a category:
<asp:DropDownList ID="CategoriesDropDown" runat="server"
DataSourceID="CategoriesDataSource" DataTextField="CategoryName"
DataValueField="CategoryID" Width="250px"
AutoPostBack = "true" />
<br /><br /><hr /><br />
<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ObjectDataSource ID="TemplatesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetTemplates" TypeName="DataLayer.ProtocolTemplate">
<SelectParameters>
<asp:ControlParameter ControlID="CategoriesDropDown" DefaultValue="0" Name="CategoryID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<table border="1" width="100%" >
<thead>
<tr>
<td align="center" colspan="4">Available templates</td>
</tr>
<tr>
<td width="25%">Name</td>
<td width="70%">Description</td>
</tr>
</thead>
<tbody>
<asp:Repeater ID="TemplatesRepeater" runat="server"
DataSourceID="TemplatesDataSource" OnItemCommand="TemplatesRepeater_ItemCommand" >
<ItemTemplate>
<tr>
<asp:MultiView ID="ItemMultiView" runat="server" ActiveViewIndex="0">
<asp:View ID="ReadOnlyView" runat = "server">
<td>
<asp:Label ID="NameLabel" runat="server"
Text= '<%# Eval("TemplateName") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server"
Text = '<%# Eval("Description") %>' />
</td>
<td>
<asp:Button ID="EditButton" runat ="server"
CommandName="edit" Text="Edit" />
</td>
<td>
<asp:Button ID="DeleteButton" runat = "server" UseSubmitBehavior="false"
CommandName = "delete" Text= "Delete"
CommandArgument = '<%# Eval("TemplateID") %>' />
<ajaxToolkit:ConfirmButtonExtender ID ="ConfirmButton" runat="server"
ConfirmText = "You are about to delete this template. Click ok to proceed"
TargetControlID = "DeleteButton" />
</td>
</asp:View>
<asp:View ID="EditView" runat="server">
<td>
<asp:TextBox ID="NameTextBox" runat ="server"
Text= '<%# Eval("TemplateName") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text = '<%# Eval("Description") %>' />
</td>
<td>
<asp:Button ID = "SaveButton" runat = "server"
CommandName= "save" Text = "Save"
CommandArgument = '<%# Eval("TemplateID") %>' />
</td>
<td>
<asp:Button ID = "CancelButton" runat = "server"
CommandName = "cancel" Text = "Cancel" />
</td>
</asp:View>
</asp:MultiView>
</tr>
</ItemTemplate>
<FooterTemplate>
<td>
<asp:TextBox ID="NameTextBox" runat ="server"
Text= '<%# Eval("TemplateName") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text = '<%# Eval("Description") %>' />
</td>
<td>
<asp:Button ID = "AddButton" runat = "server"
CommandName= "add" Text = "Add" />
</td>
</FooterTemplate>
</asp:Repeater>
</tbody>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CategoriesDropDown" EventName="SelectedIndexChanged" />
</Triggers>

</asp:UpdatePanel>
</div>
</form>
</body>
</html>

And a fraction of code behind:

protected void TemplatesRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "edit")
EditItem(e);
else if (e.CommandName == "cancel")
CancelItem(e);
else if (e.CommandName == "save")
SaveItem(e);
else if (e.CommandName == "delete")
DeleteItem(e);
else if (e.CommandName == "add")
AddItem(e);

}

private void DeleteItem(RepeaterCommandEventArgs e)
{
int TemplateID = int.Parse((string) e.CommandArgument);
DataLayer.ProtocolTemplate.DeleteTemplate(TemplateID);
this.TemplatesRepeater.DataBind();
}

I have removed the update panel, but still does not work.

The first time the page is rendered (HTTP GET) no AjaxControlToolkit.ConfirmButtonBehavior are created.

When you click on the delete button a regular postback occurs, the row is deleted and I get the following error on a browser alert:

Line: 1960
Error: Sys.ArgumentException:Value must not be null for Controls and Behaviors
Parameter name:element

The page source code contains the following javascript code:

Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ConfirmButtonBehavior, {"ConfirmText":"You are about to delete this template. Click ok to proceed","id":"ConfirmButton"}, null, null, $get('DeleteButton'));
});
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ConfirmButtonBehavior, {"ConfirmText":"You are about to delete this template. Click ok to proceed","id":"TemplatesRepeater_ctl00_ConfirmButton"}, null, null, $get('TemplatesRepeater_ctl00_DeleteButton'));
});
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ConfirmButtonBehavior, {"ConfirmText":"You are about to delete this template. Click ok to proceed","id":"TemplatesRepeater_ctl01_ConfirmButton"}, null, null, $get('TemplatesRepeater_ctl01_DeleteButton'));
});

Obviously the first $create call fails because $get('DeleteButton') returns null since 'DeleteButton' does not exist.

If you continue clicking delete buttons you continue getting these errors, no confirmation alert message is shown.

Confirm button is the simplest control in Ajax Control Toolkit. I think at least this one should work :-(


I'm getting the exact same thing, except I am using a DataList instead of a Repeater.

I have decided not to use confirm button, instead I'm using the following:

 <script type="text/javascript"> function ConfirmDelete(e) { if (!window.confirm("You are about to delete this categorie.\nClick OK to proceed, cancel otherwise")) { e.returnValue = false; if (e.preventDefault) e.preventDefault(); return false; } } </script>
<asp:ImageButton ID="DeleteButton" runat ="server"
ImageUrl ="Images/delete.png" Height="16px" Width="16px"
CommandName ="delete" ToolTip="Delete"
CommandArgument ='<%# Eval("HospitalID")%>'
OnClientClick="ConfirmDelete(event);"
/>
Did this issue get resolved? I'm also finding that my ConfirmButton control is not in an Update panel.
Please try your scenario with the recently available10301 release of the Toolkit (andASP.NET AJAX 1.0). If the problem persists, then please reply with acomplete, simple, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

ConfirmButton and GridView LinkButtons

Hi Everyone,

I would like to use the ConfirmButtonExtender when a LinkButton in a DataGrid control is clicked. The LinkButton is a TemplateColumn in the DataGrid control. I have the DataGrid in an UpdatePanel, along with the ConfirmButtonExtender control. However, the LinkButton is not visible to the ConfirmButton control when trying to set the TargetControlID property.

Is it possible to tie the ConfirmButtonExtender to a control in a DataGrid?

Hey,

You would also have to put the ConfirmButtonExtender in the template column with the linkbutton.

ConfirmButton and disabled controls

I've noticed that ConfirmButton reacts on clicking on disabled (Enable = false;) buttons.
Sometimes U don't want to see confirm dialog when clicking the button is disabled.
One small modification in .js does the job (one condition when binding onclick handler) but it would by nice to have it the toolkit.

Good point - I'll add a work item for that. Thanks!
Note this is WorkItem 1482.

Saturday, March 24, 2012

ConfirmButton & Gridview Autogenerated delete button

Any way to tie the confirmbutton control to the GridView to prompt on the delete button?

The only way to currently do this is to turn your delete column into a template column and then add the extender in there with the button:

<TemplateColumn><ItemTemplate> <asp:LinkButton id="delete" runat="server" CommandName="Delete" Text="Delete"/> <atlasToolkit:ConfirmButtonExtender ID="cbe" runat="server> <atlasToolkit:ConfirmButtonExtenderProperties TargetControlID="delete" ... /> </></ItemTemplate></TemplateColumn>

Since TemplateColumn is normally associated with a DataGrid, does this also work for the TemplateField associated with the GridView? I am getting errors when I try to execute this within the TemplateField: "Assertion Failed: unrecognized tag atlascontroltoolkit:confirmbuttonbehavior". Is there anything special I need to do to use this within a GRIDVIEW?

ConfirmButton - Is it possible to control the button text in the pop-up?

Does anyone know if it is possible to control the button text in the pop-up? I would like to set the button text according to multi-language settings for the application.

Thanks,

Dave

Nop.. you can not control the text of the button in the popup. Since it depends on the client's browser language selection. If you need such customized popup try window.shomodalDialog or window.createPopup(); and put your own buttons.


Sounds like a perfect place to use the modalpopup extender to me!

Jason