Showing posts with label confirm. Show all posts
Showing posts with label confirm. Show all posts

Monday, March 26, 2012

confirmbuttonextender-advanced

I am using a confirm button extender to fire before the user updates a database. What I would like to do is gather all of the "changes" that will be made and display them in the alert...

Example:

--button 1 sub--

confirmbuttonextender1.confirmtext = textbox1.text & textbox2.text & dropdown1.selectedvalue etc.


Here is the problem... the string is not persisted until a postback takes place... so before someone says use a partial page update or anything that triggers an update... don't... ;)

so basically I need a way to gather the information from the objects BEFORE a postback takes place so that when the user clicks the button the alert will tell the user what changes are about to be made.

Thanks for the help!

You're right, it won't work with server-side script. It would be very simple to write your own javascript confirm and forget about the extender.

------------------
When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


yeah... not quite so simple....

anymore help would be great

ConfirmButtonExtender...easy right? Well...

Please help. I'm new to AJAX and the AJAX Toolkit release is new as of yesterday.

I was using code that adds an attribute for a confirm dialog to my button. It works; but I yesterday removed it to start using AJAX.

- I downloaded and installed the Toolkit last night.

- I followed the HDI (How Do I) video to setup VS 2005 Toolbox to display the new AJAX controls.

- I followed the HDI video on using the ConfirmButtonExtender.

- I have a ScriptManager control on my page.

- By following the HDI video, I succeeded with ConfirmButtonExtender in a practice project before trying it in my development project.

So I click the submit button on another page; and now I can't get the scheme to work. Why no confirm message?

Placing the ConfirmDialogExtender allows me to specify which button control to extend. The HTML looks like this:

<asp:ImageButtonID="imbContinue"runat="server"AccessKey="C"ImageUrl="~/images/Continue.gif"TabIndex="5" /><cc1:ConfirmButtonExtenderID="ConfirmButtonExtender1"TargetControlID="imbContinue"ConfirmText="Please confirm!"runat="server"></cc1:ConfirmButtonExtender>
My project existed before AJAX was installed. Do I need to prepare the project somehow to enable AJAX?

(I get NO errors. AJAX seems to be installed properly.)

My next question is going to be how can I connect a custom string to the Button/ConfirmButtonExtender? I build a string during postbacks that occur before the confirmation click occcurs. I thought I'd assign the string to the ConfirmText property under Extender properties on the button.

I would also like to mention that, by following the HDI video, I succeeded with ConfirmButtonExtender in a practice project before trying it in my development project.


Also, I have a ScriptManager control on the dysfunctional page.


I did a few tests.

1. Created a simple page like that demonstrated in the HDI video. It doesn't work in my existing project.

2. Created a new website using the AJAX-Enabled Website template. Then I created the same simple page in this project

Looking at web.config files...Many differences.

I guess I'll try migrating my project to an AJAX-Enabled project.


I copied sections of web.config that existed in the AJAX-Enabled Website project to the web.config of my existing website project.

I had to make sure not to have duplicate sections in my resultant web.config.

I noticed pages on the AJAX-Enabled website specify an updated DOCTYPE. It formerly was XHTML Transitional 1.0. Now it's as follows:

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

I hope I don't have to update the DOCTYPE on all my pages. But maybe it's not a big deal; we'll see.

Also, I had 31 warnings about "schema information not found..."

My research showed that people eliminated these warnings by commenting out the following sections (It worked for me, too):

<!--system.web.extensions-->

<!-- system.webServer>

ConfirmButtonExtender,Please Help Me

Hi,

I have a problem in ConfirmButtonExtender.

I am using ConfirmButtonExtender and when i run it,it pop up the Confirm Dialog with OK and CANCEL Button.

So,I need the value or Id of OK and Cancel Button.

My Code:

<Ajax:ToolkitScriptManager ID="ScrMgr" runat="server" EnablePartialRendering="true" />
<div>
<asp:Button ID=btn runat=server Text=Redirect OnClick="btn_Click1" />
<Ajax:ConfirmButtonExtender ID="confirm"
runat="server"
OnClientCancel="0"
ConfirmOnFormSubmit="false"

ConfirmText="Are you sure want to redirect?"
TargetControlID="btn">
</Ajax:ConfirmButtonExtender>

</div>

How can i do this?

Please Help..

By:Vasu

If you click on OK it returns true otherwise it returns false.

can you tell me why you need ID of that button?


Hi,

I'm not sure why you want to achieve this too. But you can use the following method:

1. Add a modalPopupExtender and corresponding panel with ok & cancel button in it to the page

2. Use this modalPopup instead of default confirm window by setting DisplayModalPopupID property to the modalPopupExtender's id

<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server"
TargetControlID="LinkButton" BehaviorID="cbe"DisplayModalPopupID="aaa"
ConfirmText="Are you sure you want to click the LinkButton?"
OnClientCancel="cancelClick" />

3. Get ok & cancel button's id via

$find($find("cbe").get_displayModalPopupID()).get_OkControlID() / get_CancelControlID()

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.

Confirmbuttonextender how to stop confirm if validation fails

I am trying to use the confirmbuttonextender, but I only want to show the confirm message if some validation passes. I have a button that calls a javascript function to perform some validation. If validation fails the javascript returns false and would stop the button from submiting. I tried setting the ConfirmOnFormSubmit=true, but when I do this the javascript function doesn't seem to be called. When it is false the confirm message appears, then I click OK, then the javascript is called, but the button still submits even thought the function returned false. Any help would be appreciated, I haven't found any working example.

Thanks,
Matt

My code:

<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" TargetControlID="btnDelete" runat="server"
ConfirmText="Are you sure you want to delete?" ConfirmOnFormSubmit=true ></ajaxToolkit:ConfirmButtonExtender>
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClientClick="DeleteEquipFunction();" />


<script type="text/javascript">
function DeleteEquipFunction()
{
//some validation
return false;
}
</script>

I think, if this case you should not use ConfirmButtonExtender, because AJAX creates a function on init event of page, which is then binded to command button.

Can you change your code like this.

<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClientClick="return DeleteEquipFunction();" />

<script type="text/javascript">
function DeleteEquipFunction()
{
//some validation
if(validated) //validated is true
{
return confirm("Are you sure you want to delete?");
}
return false;
}
</script>


Thanks Ritesh.

I wound up following your suggestion and it works good.

I thought the ConfirmOnFormSubmit property was added to the confirmbutton so the confirm would not as the last action before server submission, but it seems to fire before onClientClick, and therefore you can't seem to stop it. I love the Ajax toolkit, but it seems there are some obscure properties of these controls that are not clearly defined on Microsofts website or any book I have found.

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

Confirm GridView row delete with ModalPopup

Hi,

I have a GridView with a delete Button on each line, to delete that row. This works fine usingCommandName="Delete" propertyon the button and theRowDeleting Event on the GridView.

What I want is to use the ModalPopup to make a delete confirmation, but, I can't put this to work. The RowDeleting Event doen's work anymore.

What should I do?

This is the code:

<ItemTemplate> <asp:ImageButton ID="ibDelete" runat="server" CausesValidation="False" CommandName="Delete" ImageUrl="../../UserFiles/Images/ico_del.gif" ToolTip="delete row"/> <asp:Panel ID="pnlPopUp" runat="server" Style="display: none" CssClass="modalPopup"> <asp:Panel ID="pnlDragPopUp" runat="server" Style="cursor: move;background-color:#DDDDDD;border:solid 1px Gray;color:Black"> <div> <p>Are you sure you want to delete this item?</p> </div> </asp:Panel> <div> <p style="text-align: center;"> <asp:Button ID="OkButton" runat="server" Text="Yes" /> <asp:Button ID="CancelButton" runat="server" Text="Cancel" /> </p> </div> </asp:Panel> <ajax:ModalPopupExtender ID="ModalPopupExtender" runat="server" TargetControlID="ibDelete" PopupControlID="pnlPopUp" BackgroundCssClass="modalBackground" OkControlID="OkButton" CancelControlID="CancelButton" DropShadow="true" PopupDragHandleControlID="pnlDragPopUp" /> </ItemTemplate>
 The GridView Event:
 
 
Protected Sub MyGridView_RowDeleting(ByVal senderAs Object,ByVal eAs GridViewDeleteEventArgs)Dim myConnetionAs SqlConnection =New SqlConnection(erpConn)Dim delCommandAs SqlCommand = myConnetion.CreateCommand() delCommand.CommandText ="myQuery" delCommand.Parameters.Add("@dotnet.itags.org.Adress", SqlDbType.NVarChar).Value = MyGridView.DataKeys(e.RowIndex).Values(0).ToString() myConnetion.Open() delCommand.ExecuteNonQuery() myConnetion.Close() GetUser()End Sub

Anyone?Crying


Hi Cseven,

Would you please remove theOkControlID="OkButton"

<ajax:ModalPopupExtender ID="ModalPopupExtender" runat="server"
TargetControlID="ibDelete"
PopupControlID="pnlPopUp"
BackgroundCssClass="modalBackground"
OkControlID="OkButton" //remove this item
CancelControlID="CancelButton"
DropShadow="true"
PopupDragHandleControlID="pnlDragPopUp" />

In your case, it won't post back, so that's cause the problem.

By the way, in your case , there are severalModalPopupExtenders and Panels in a page. It is cool but not an efficient way.

I hope this help.

Best regards,

Jonathan


the modalpopupextender takes control of its targetcontrol...so in your case the ibDelete button event, which fires the RowDeleting, is being overridden on the client

you have two options:

1) use the old hidden button hack and show your modalpopup programatically. Place another button right above your modalpopupextender and hide it via css...then set your modalpopupextender targetcontrolid to that button... now in your code-behind inside your gridview_rowcommand event...put a logic statement checking e.commandname ...if it equals "Delete" then call ModalPopupExtender.Show()...

2) create a webmethod that deletes the row manually and call it with the onokscript via the modalpopupextender

Confirm functionality with modalpopup

Hi all,

I have been trying to do the following:
Press the delete button in a grid and show a custum modal popup. My idea was to cut the __dopostback script of the button and paste it on the ok button script of the popup. Like so:

ConfirmationButton.ascx:

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="ConfirmationButton.ascx.cs" Inherits="UserControls_Misc_ConfirmationButton" %>
<asp:Button ID="Confirm" runat="server" Text="Button" UseSubmitBehavior="false" OnClick="Confirm_Click" />

ConfirmationButton.ascx.cs:

protected void Page_Load(object sender, EventArgs e)
{

string dopostback = Page.ClientScript.GetPostBackEventReference(Confirm, "");
if (dopostback.IndexOf("__doPostBack") > -1)
dopostback = dopostback.Replace("__doPostBack", "Confirmation");
else
throw new Exception("No __doPostback found in Confirmation button");
Confirm.Attributes.Add("OnClick", dopostback+";return false;");
JavaScriptGenerate();

}

public void JavaScriptGenerate()
{
if (!Page.ClientScript.IsClientScriptBlockRegistered("Confirmbutton"))
{

StringBuilder sb = new StringBuilder();

sb.Append("<script language=\"javascript\">");
sb.Append("function Confirmation(eventTarget, eventArgument)");
sb.Append("{");
sb.Append("$object('MessageBox')._onOkScript = function(){__doPostBack(' + eventTarget + ',' + eventArgument + ');};");
sb.Append("$object('MessageBox')._show();");
sb.Append("}");
sb.Append("</script>");

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Confirmbutton", sb.ToString());
}
}

protected void Confirm_Click(object sender, EventArgs e)
{
int a = 0;
}

And my ASPX looks like this:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="TEST_Default" %>

<%@dotnet.itags.org. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %>
<%@dotnet.itags.org. Register src="http://pics.10026.com/?src=../UserControls/Misc/ConfirmationButton.ascx" TagName="ConfirmationButton"
TagPrefix="uc1" %>
<!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>
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
</atlas:ScriptManager>
<uc1:ConfirmationButton ID="ConfirmationButton1" runat="server" />
</div>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none">
<table cellpadding="0" cellspacing="0" border="0">
<tr style="font-weight: bold; color: white; background-color: dimgray;">
<td>
<asp:Label ID="HeaderLabel" runat="server" Text="Header"></asp:Label></td>
</tr>
<tr>
<td>
<asp:Label ID="MessageLabel" runat="server" Text="Message"></asp:Label></td>
</tr>
<tr>
<td align="right">
<asp:Button ID="OkButton" runat="server" Text="Ok" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
<atlastoolkit:modalpopupextender id="ModalPopupExtender1" runat="server">
<atlasToolkit:ModalPopupProperties BackgroundCssClass="modalBackground" CancelControlID="CancelButton"
PopupControlID="Panel1" TargetControlID="PopupButton" ID="MessageBox" />
</atlastoolkit:modalpopupextender>
<div style="display: none">
<asp:LinkButton ID="PopupButton" runat="server"></asp:LinkButton>
</div>
</form>
</body>
</html
The code above is just a sample of my code hopefully enough for you guys to understand the problem.

I have gotten as far as showing the popup, but when I press the ok button on the popup, a roundtrip happens and nothing else. Why isn't going to the Confirm_click code?

Maybe this whole appoach is wrong. Hope you can help me

Oez

Hey Oez,

I blogged on how I got this scenario to work recently.
Creating a confirmation using the ModalPopup

Thanks for doing this - great blog post. This is something I've been thinkng about so I've logged asIssue 1369. I think the cleanest way for us to do this is to expose the functionality via ConfirmButton rather than via ModalPopup.

Thanks!


I would like to thank Alan for his great blog. This really pushed me in the right direction. I've used his sample to create the functionality I was after.

Intercept the button postback, show a modal popup and if 'yes' is pressed continue with the postback else do nothing.
Here is my sample code. Create a new atlas web project. On the default page create the following code:


<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_default" %>
<%@.RegisterSrc="MessageBox.ascx"TagName="MessageBox"TagPrefix="uc1" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Modal Confirmation</title>
<styletype="text/css">
body {
font:normal10pt/13ptArial,Verdana,Helvetica,sans-serif;
color:#666;
margin:20px;
}

/*Modal Popup*/
.modalBackground {
background-color:#000;
filter:alpha(opacity=80);
opacity:0.8;
}
.modalPopupimg {
border:solid5px#fff;
}
.modalPopup-text {
display:block;
color:#000;
background-color:#fff;
text-align:center;
border:solid2px#000;
padding:10px;
}
.modalPopup-textinput {
width:75px;
}

.feedback
{
color:#00cc00;
font-weight:700;
}
</style>

</head>
<body>
<formid="form1"runat="server">
<atlas:ScriptManagerID="ScriptManager1"runat="server"/>
<h2>Modal Confirmation</h2>
<divclass="demo">
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateFieldShowHeader="False">
<ItemTemplate>
<asp:ButtonID="DeleteButton"runat="server"Text="Delete"/>
</ItemTemplate>
<AlternatingItemTemplate>
<asp:LinkButtonID="DeleteButton"runat="server">Delete</asp:LinkButton>
</AlternatingItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<uc1:MessageBoxID="MessageBox1"runat="server"/>

</div>
</form>
</body>
</html>

And code behind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
publicpartialclass_default : System.Web.UI.Page
{
protectedvoid Page_Load(object sender,EventArgs e)
{
DataTable dt =newDataTable();
for (int i = 0; i <= 5; i++)
{
DataRow row = dt.NewRow();
dt.Rows.Add(row);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}

protectedvoid GridView1_RowDataBound(object sender,GridViewRowEventArgs e)
{
WebControl delete = (WebControl)e.Row.FindControl("DeleteButton");
if (delete !=null)
MessageBox1.ConnectButton(delete);
}
}
Now add a usercontrol called MessageBox to the project.
<%@.ControlLanguage="C#"AutoEventWireup="true"CodeFile="MessageBox.ascx.cs"Inherits="MessageBox" %>
<%@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlastoolkit" %>
<asp:PanelID="ConfirmtionPanel"runat="server"CssClass="modalPopup"Style="display: none">
<divclass="modalPopup-text">
Are you sure you want to delete this item?<br/>
<br/>
<asp:ButtonID="YesButton"runat="server"Text="Yes"/>
<asp:ButtonID="NoButton"runat="server"Text="No"/>
</div>
</asp:Panel>
<atlastoolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server">
<atlastoolkit:ModalPopupPropertiesPopupControlID="ConfirmtionPanel"TargetControlID="FakeButton"
OkControlID="YesButton"OnOkScript="onYes()"CancelControlID="NoButton"OnCancelScript="onNo()"
BackgroundCssClass="modalBackground"ID="msgBox"/>
</atlastoolkit:ModalPopupExtender>
<divstyle="display:none">
<asp:LinkButtonID="FakeButton"runat="server">Fake</asp:LinkButton>
<asp:HiddenFieldID="eventTarget"runat="server"></asp:HiddenField>
<asp:HiddenFieldID="eventArgument"runat="server"></asp:HiddenField>
</div>

And the code behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using AtlasControlToolkit;
publicpartialclassMessageBox : System.Web.UI.UserControl
{
privatestring _msgBoxId;

protectedvoid Page_Init(object sender,EventArgs e)
{
//This is so you can add multiple MessageBox usercontrols to a page and the ModalPopupProperties will be unique.
_msgBoxId =this.ClientID +"_" + msgBox.ID;
msgBox.ID = _msgBoxId;
}

protectedvoid Page_Load(object sender,EventArgs e)
{
// Expose the __doPostBack function to programmatically call it from javascript
Page.ClientScript.GetPostBackEventReference(this,String.Empty);
if (!Page.ClientScript.IsClientScriptBlockRegistered("MessageBox"))
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"MessageBox", GetScript());
}

publicstring GetScript()
{
StringBuilder sb =newStringBuilder();
sb.Append("<script type=\"text/javascript\">");
sb.Append("function onYes() {");
sb.Append("var eventTarget = $('");
sb.Append(eventTarget.ClientID);
sb.Append("').value;");
sb.Append("var eventArgument = $('");
sb.Append(eventArgument.ClientID);
sb.Append("').value;");
sb.Append("var postBack = new Sys.WebForms.PostBackAction();");
sb.Append("postBack.set_target(eventTarget);");
sb.Append("postBack.set_eventArgument(eventArgument);");
sb.Append("postBack.performAction();");
sb.Append("}");
sb.Append(" ");
sb.Append("function onNo() {");
sb.Append("//no postback necessary \n");
sb.Append("} ");
sb.Append("</script>");

return sb.ToString();
}

publicvoid ConnectButton(WebControl Confirm)
{
string dopostback = Page.ClientScript.GetPostBackEventReference(Confirm,"");
if (dopostback.IndexOf("__doPostBack") > -1)
dopostback = dopostback.Replace("__doPostBack","Confirmation").Replace(")",",'" + _msgBoxId +"')");
else
thrownewException("No __doPostback found in Confirmation button");
Confirm.Attributes.Add("OnClick", dopostback +";return false;");
JavaScriptGenerate();
}
privatevoid JavaScriptGenerate()
{
if (!Page.ClientScript.IsClientScriptBlockRegistered("Confirmbutton"))
{
StringBuilder sb =newStringBuilder();
sb.Append("<script language=\"javascript\">");
sb.Append("function Confirmation(eventTarget, eventArgument, msgBoxId)");
sb.Append("{");
sb.Append("$('");
sb.Append(eventTarget.ClientID);
sb.Append("').value=eventTarget;");
sb.Append("$('");
sb.Append(eventArgument.ClientID);
sb.Append("').value=eventArgument;");
sb.Append("$object(msgBoxId)._show();");
sb.Append("}");
sb.Append("</script>");

Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"Confirmbutton", sb.ToString());
}
}
}

Hopes this helps for issue 1369. If you guys have any ideas to improve this code, to make it more flexible or better code, I would love see that...do say it...more comments...I know...

Excellent to hear that my post helped! That's what the forums and tech blogs all about.

Alante,

I'm trying to use your code, and it's working in the single form, but not in the page with MasterPage, i changed the javacode to

postBack.set_target('<%=YesButton.ClientID %>');

it's posting back but it's not calling theYesButton_Click event Should I change also the

postBack.set_eventArgument(''); statement to somethign else? I would really apppreciate your help.


A commenter on my blog posted the solution to your problem FrenchilnLA. He got it to work with the master page by using the full reference to the control id, ie. postBack.set_target('ct100_masterName_ YesButton');


I finally add the following code at Page Load event:

string strEvent = ClientScript.GetPostBackEventReference(YesButton,string.Empty);

YesButton.Attributes.Add(

"onclick", strEvent);

Is it funny that we have to force a bostback to a server control that has an Click event ?

This control extender (modal Popup) should allow to be triggered from Server code, and the yes and no button should post back as well.

Thank you anyway I really appreciated your help.

Confirm Extender + Modal Popup -> Call JavaScript on the load, and exit.

I have a Confirm Extender workign with a modal popup extender.

What I'd "like" to do is when the button that launches both is clicked, to run some client script to populate some fields. This saves me from doing it on the server. however, even using OnCLientClick on the button initiating all of this it doesn't work.

Any thoughts?

Also, when I click the OK button close the modal popup confirm box.. .(say that 10x as fast as you can), it would be better for it to close right away, rather than close when the server is done processing.

Is it possible to run script before it hits the server to make the display:none; again?

Hi RTernier,

RTernier:

What I'd "like" to do is when the button that launches both is clicked, to run some client script to populate some fields. This saves me from doing it on the server. however, even using OnCLientClick on the button initiating all of this it doesn't work.

Here is a workable example which you can compare with yours.

<%@. Page Language="C#" %><%@. Import Namespace="System.Threading" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { Thread.Sleep(3000); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style> .modalBackground { background-color:Gray; filter:alpha(opacity=70); opacity:0.7; } .modalPopup { background-color:#FFD9D5; border-width:3px; border-style:solid; border-color:Gray; padding:3px; width:250px; } </style></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager><%=DateTime.Now.ToString()%> <asp:Button ID="Button1" runat="server" Text="Button" /><ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="Button1" DisplayModalPopupID="ModalPopupExtender1" > </ajaxToolkit:ConfirmButtonExtender> <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Style="display: none"> Are you sure? <asp:Button ID="btnOk" runat="server" Text="Ok" /> <asp:Button ID="btnCancel" runat="server" Text="Cancel" /> </asp:Panel> <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1" PopupControlID="Panel1" CancelControlID="btnCancel" BackgroundCssClass="modalBackground" OkControlID="btnOk"> </ajaxToolkit:ModalPopupExtender> <script type="text/javascript" language="javascript"> function pageLoad(){ $find("<%=ModalPopupExtender1.ClientID%>").add_showing(onMPEShowing); } function onMPEShowing(){ //your javascript code here to add fields or do anything what you want. } </script> </form></body></html>

RTernier:

Also, when I click the OK button close the modal popup confirm box.. .(say that 10x as fast as you can), it would be better for it to close right away, rather than close when the server is done processing.

Is it possible to run script before it hits the server to make the display:none; again?

It will be hidden right after be clicked. Please see my sample

Hope this helps.

Best regards,

Jonathan


I can not say how grateful I am for this solution. Wanted same functionality in my app.

I have 1 question though. Is there any client script reference for methods like add_showing etc. I also wanted to do some client side scripting on modal popup closing ..and i just guessed the function (must be my luck day) add_hiding..which worked beautifully!

However, I would still love a client side script reference for the same. Please advise. Thanks!

Confirm deleting using ModalPopup in GridView

Hi there!

I want to confirm deleting row from GridView using a ModalPopup Extender. Please tell me, how can I do it?

I.e., how to show ModalPopup Panel when user click a Delete button, and how to cansel deleting when user click a Cansel button on ModalPopup Panel and confirm deleting when click a OK Button.

Please, someone, help meCrying


check this article to show modalpopup and do postback when you click the 'OK' button on the ModalPopup.

http://www.aspdotnetcodes.com/ModalPopup_Postback.aspx

Confirm Button Extension with Wizard buttons?

Hi

I would like to use the AJAX confirm button extension, but I am trying to attach it to the "FinishButton" that is automatically created with the ASP Wizard.

So in a nutshell when a user clicks the "finish" button in my wizard a message box will pop up asking the user if they are sure they would like to continue.

I'm using VWD2005 express and scripting in visual C#.

Please can someone help me out or point me in the right direction?

Cheers!!!

Hi

I managed to solve this one! Woooohoooo.

If anyone is interested then here's my ASP. You need to put the button extended inside the Finish Navigation Template itself.

<FinishNavigationTemplate>

<cc1:ConfirmButtonExtenderID="ConfirmButtonExtender1"runat="server"TargetControlID="FinishCompleteButton"ConfirmText="Are you sure you want to place this order?">

</cc1:ConfirmButtonExtender>

<asp:ButtonID="FinishPreviousButton"runat="server"Text="Previous"CommandName="MovePrevious"/>

<asp:ButtonID="FinishCompleteButton"runat="server"Text="Finish"OnClientClick="Wizard1_FinishButtonClick"CommandName="MoveComplete"/>

<asp:ButtonID="CancelButton"runat="server"Text="Cancel"CommandName="Cancel"/>

</FinishNavigationTemplate>

confirm button extender in a datagrid

Hi all,

Quick Question.

How can you use a confirm button extender in a datagrid?

So if you have a datagrid with 10 rows, each with a delete link button at the end and you want the confirm dialouge to popup everytime you click on any of the 10 delete link buttons. How do you do it?

Thanks in advance.

Use the rowdatabound event to add an attribue to thelinkbutton("DELETE"), assuming the linkbutton is in the first column ofthe gridview:


If e.Row.RowType = DataControlRowType.DataRowThen
Dim lbAs LinkButton
lb = e.Row.Cells(0).Controls(0)
lb.Attributes.Add("onclick", "javascript:return confirm('Are you sure you want to delete this row?');")
End If
OnClientClick="return confirm('Are you sure you want to delete
this item?');"

However,to make that work, you'll need to convert the Delete button into aTemplate field. The following post gives more details about this:

http://p2p.wrox.com/topic.asp?TOPIC_ID=45586

cheers


Thanks,

I allready have that. I allready have a javascript confirm dialouge.

I wanted to use the confirm button exetender in the ajax tool kit. I know its exactly the same, but i thought i would try the "new thing".

Thanks for your response though.


Just add a confirmbuttonextender in the template for the column so that one gets created for every row of the grid.

i did this...

<

asp:GridViewID="grvReservas"runat="server"CellPadding="4"GridLines="None"Height="81px"Style="z-index: 115; left: 58px; position: absolute; top: 328px"Width="691px"OnRowDeleting="grvReservas_RowDeleting"OnSelectedIndexChanged="grvReservas_SelectedIndexChanged"ForeColor="#333333"><FooterStyleBackColor="#507CD1"ForeColor="White"Font-Bold="True"/><RowStyleBackColor="#EFF3FB"/><SelectedRowStyleBackColor="#D1DDF1"Font-Bold="True"ForeColor="#333333"/><PagerStyleBackColor="#2461BF"ForeColor="White"HorizontalAlign="Center"/><HeaderStyleBackColor="#507CD1"Font-Bold="True"ForeColor="White"/><AlternatingRowStyleBackColor="White"/><Columns><asp:CommandFieldShowDeleteButton="True"/><asp:TemplateField><ItemTemplate><asp:ImageButtonID="ImageButtonDelete"runat="server"CausesValidation="false"CommandName="ImageButtonDelete"ImageUrl="../images/eliminar.jpg"OnClick="ImageButtonDelete_Click"Visible="true"/><cc1:ConfirmButtonExtenderID="ConfirmButtonExtender1"runat="server"ConfirmText="?Esta seguro que desea cancelar la reserva seleccionada?"TargetControlID="ImageButtonDelete"></cc1:ConfirmButtonExtender></ItemTemplate></asp:TemplateField><asp:ImageField></asp:ImageField></Columns><EditRowStyleBackColor="#2461BF"/>

</asp:GridView>

but in ImageButtonDelete_Click method, how do i know which row is selected?????


You could add a commandargument to the imagebutton with some kind of ID value that identifies the data that you want to delete.
how can i add a commandargument to the imagebutton with the ID value ?

Hookup to the rowdatabound event of the gridview and then set the property in there.

Confirm button extender and validation controls

Hi,

I am using the confirm button extender in conjunction with some required field validators. Is there any way to stop the extender popping up if the page isn't valid? They are clearly both fired at the same time client-side from the button click event.

Andy

Im wondering this too...did you find a solution?

I only want a confirmation dialog if it passes all validation first.

Confirm button extender

Now this is a very useful extender but I wonder if anyone has tried to enhance its looks ?

I was looking for a confirm button like the ballons i can see on

http://www.mainetoday.com/wendy/toolbar/demo.html

when i hover over the menu items at the top

To have a custom Confirm Button you could use ModalPopup instead. If you would like it to show the same way it is showing on that linked page you could use the HoverMenu and style it as you would like. We had a balloon popup extender in the making but it is not close to being done any time soon.

Conditional ConfirmButtonExtender

Hi!!

Just wondering if this was possible...

I've got some buttons that sometimes I want to confirm, and at other times I don't. For example, if I'm taking an order for a certain quantity (e.g. 1,000) I might want to confirm that the user is happy with this, whereas if it's for a low amount (e.g. 1 or 2) I don't need to confirm this.

Has anyone got any ideas how to achieve this with the confirmButtonExtender, or is it a case of writing manual javascript and using the OnClientClick property of the asp:Button?

Many thanks in advance for your help!

Regards,

James

I'm thinking you might modify a customized ConfirmButton slightly so that it knows to look at some page state (JS variable, element value, etc.) before displaying the confirm dialog. Shouldn't be much more than an additional line or two, I'm not thinking...

Conditional Animation

Hi all,

I have an animation question.

I have a delete button and confirm delete button. So when you first click delete, I would show you the confirm delete button. After you click the confirm delete button, then i will delete the items.

The animation i would like is when you click "Delete", the area where the confirm delete button "FadeIn", and when you click "ConfirmDelete", first, a message will be display in the area stating that certain records has been deleted, while the area where the confirm delete button is slowly fade out. Liek the typical basecamp type of thing.

The problem I'm having is when Delete button is clicked, at first it did "FadeIn", but without confirmdelete button clicked, it faded out by itself. What am I doing wrong? If I take out the "fadeout" tag, and I have a conditional statement there. seems like it's working. Only when the "confirmDelete" button is clicked, would the script execute. As soon as I put the "fadeout" tag back in, i don't udnerstand why "fadout" was execute automatically.

<atlas:UpdatePanelID="UpdatePanel1"runat="server"Mode="conditional">

<ContentTemplate>

<divid="Warning"visible="false"runat="Server">

<p><asp:LiteralID="WarningMessage"runat="server"/></p>

<divclass="confirm">

<asp:ButtonID="ConfirmDeleteTrash"CssClass="ctrolSubmit"Text="Delete"OnClick="DeleteOrTrashItems"runat="server"/> or<ahref="#">Cancel</a>

</div>

</div>

</ContentTemplate>

<Triggers>

<atlas:ControlEventTriggerControlID="Delete"EventName="Click"/>

<atlas:ControlEventTriggerControlID="ConfirmDeleteTrash"EventName="Click"/>

</Triggers>

</atlas:UpdatePanel>

<atlasToolkit:UpdatePanelAnimationExtenderID="upae"runat="server">

<atlasToolkit:UpdatePanelAnimationPropertiesTargetControlID="UpdatePanel1">

<Animations>

<OnUpdating>

<FadeInDuration="2"Fps="25"

AnimationTarget="Warning"

minimumOpacity=".2"

/>

</OnUpdating>

<OnUpdated>

<Sequence>

<Parallelduration="5"Fps="25">

<ConditionConditionScript="$('ConfirmDeleteTrash').click">

<FadeOut/>

<ScriptActionScript="alert('ConfrimDeleteTrash cicked!');"/>

</Condition>

</Parallel>

</Sequence>

</OnUpdated>

</Animations>

</atlasToolkit:UpdatePanelAnimationProperties>

</atlasToolkit:UpdatePanelAnimationExtender>

Hi,

This seems to be a duplicate of the post inthis thread.

Thanks,
Ted