Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts

Monday, March 26, 2012

ConfirmButtonExtender inside templatefield inside gridview gives an error but works fine

Inside a gridview i have a button to delete a record (button 3). There is a ConfirmButtonExtender to prevent a administator from deleting the wrong record.

This works fine, but the page gives an error (IE6 in the statusbar). Also some TextBoxWatermarkExtenders placed after the gridview only work after a postback. When I take out the ConfirmButtonExtender it works fine. I can't place the ConfirmButtonExtender outside the gridview because it doesn;t find button3 than.

Anyone? By the way: the ConfirmButtonExtender does work like it's supposed to!

... <asp:TemplateField Visible="False" ShowHeader="False"> <ItemStyle Width="35px" HorizontalAlign="Left"></ItemStyle> <ItemTemplate> <asp:Button ID="Button3" runat="server" Style="background-attachment: fixed; background-color: transparent; background-image: url(http://blabla.gif); background-repeat:no-repeat ; border-top-width: thin; border-left-width: thin; border-left-color: moccasin; border-bottom-width: thin; border-bottom-color: moccasin; border-top-color: moccasin; border-right-width: thin; border-right-color: moccasin;" Width="32px" tooltip="Verwijder WV (definitief!!!!!)" CommandArgument='<%# eval("Kop1AlgVpNummer")%>' Height="30px" OnCommand="Button3_Command" BorderColor="#FFE0C0" BorderStyle="None" /> <ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="Button3" ConfirmText="Zeker weten?"></ajaxToolkit:ConfirmButtonExtender> </ItemTemplate> </asp:TemplateField>...

Seems to work fine for me (the error on postback's just due to the way I create the data):

<%@. Page Language="C#" AutoEventWireup="true" Title="Controls in a Repeater Tests" %><script runat="server"> protected void Page_Load(object sender, EventArgs e) { System.Data.DataTable table = new System.Data.DataTable(); table.Columns.Add(new System.Data.DataColumn("Value", typeof(string))); foreach (string value in "one,two,three,four,five".Split(',')) { System.Data.DataRow row = table.NewRow(); row["Value"] = value; table.Rows.Add(row); } Repeater1.DataSource = new System.Data.DataView(table); Repeater1.DataBind(); }</script><%@. 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 id="Head1" runat="server"> <title>Sample Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="SM" runat="server" /> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <asp:Button ID="Button" runat="server" Text='<%# Eval("Value")%>' /> <ajaxToolkit:ConfirmButtonExtender ID="CBE" runat="server" TargetControlID="Button" ConfirmText='<%# Eval("Value")+" - Really?"%>' /> <hr /> </ItemTemplate> </asp:Repeater> </form></body></html>

Mmmm, maybe I should add that my gridview is inside an updatepanel also? Yours' is in a repeater......

Or should I paste the complete code?


 OK, here is the complete code: 
1<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="overzicht.aspx.vb" Inherits="_overzicht" %>2<%@. MasterType virtualpath="~/Masterpage.master" %>34<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">5 <asp:ScriptManager runat="server" id="SC1"></asp:ScriptManager>6 <div>7 <asp:UpdatePanel ID="UpdatePanel1" runat="server">8 <ContentTemplate>9 <em><span style="FONT-SIZE: 8pt; COLOR: #006600">10 <asp:Label ID="Label8" runat="server" Font-Size="8pt" Text="Status:"></asp:Label><br/>11 <asp:DropDownList style="FONT-SIZE: 8pt; FONT-FAMILY: 'Lucida Sans'" id="ddl_snel" runat="server" Width="49px" Height="19px" AutoPostBack="True" OnSelectedIndexChanged="ddl_snel_SelectedIndexChanged">12 <asp:ListItem ><=3</asp:ListItem>13 <asp:ListItem >=3</asp:ListItem>14 <asp:ListItem >=2</asp:ListItem>15 <asp:ListItem >=1</asp:ListItem>16 <asp:ListItem >=0</asp:ListItem>17 </asp:DropDownList></span></em>18<br/>19 <asp:GridView id="GridView_s" runat="server" Width="56px" AllowPaging="True" ShowHeader="False" PageSize="30" HorizontalAlign="Left" Height="600px" GridLines="None" DataSourceID="SqlDataSource_s" DataKeyNames="Kop1AlgVpnummer" AutoGenerateColumns="False" Font-Size="8pt" Font-Strikeout="False">20 <Columns>21 <asp:TemplateField>22 <ItemTemplate>23 <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Kop1AlgVpNummer", "~/MemberPaginas/details.aspx?WVnummer={0}")%>'24 Text='<%# Eval("Kop1AlgVpnummer", "{0}")%>' ToolTip='<%# Eval("titel")%>'></asp:HyperLink>25 </ItemTemplate>26 </asp:TemplateField>27 </Columns>28 <PagerSettings Mode="NextPreviousFirstLast" />29 <RowStyle HorizontalAlign="Left" VerticalAlign="Top" Font-Italic="True" Font-Size="8pt" ForeColor="Maroon" />30 <PagerStyle Font-Size="7pt" Font-Overline="False" />31 </asp:GridView>32<asp:SqlDataSource ID="SqlDataSource_s" runat="server" ConnectionString="<%$ ConnectionStrings:WV-ConnectionString%>"33 SelectCommand="SELECT Kop1AlgVpnummer, titel FROM DATA WHERE (status <= 3) ORDER BY Kop1AlgVpnummer DESC">34</asp:SqlDataSource>3536 </ContentTemplate>37 </asp:UpdatePanel>38 </div>39</asp:Content>4041<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">42 <div style="FONT-SIZE: 8pt"><br />43 <asp:UpdatePanel runat="server" id="up2">44 <ContentTemplate>45 <asp:Button style="LEFT: 0px; POSITION: relative; TOP: -21px" id="Button6" runat="server" Text="print overzicht (PDF)" Font-Size="8pt" Font-Bold="True" Width="132px" ForeColor="#FF0000" BackColor="#0000C0" ToolTip="Print huidige overzicht..."></asp:Button>46 <asp:Button style="LEFT: 94px; CURSOR: hand; POSITION: relative; TOP: -21px" id="Button4" runat="server" Text="Mijn WV's" Font-Size="8pt" Font-Bold="True" BorderStyle="Ridge" ForeColor="#0000C0" BackColor="#FFC080" ToolTip="Laat alleen 'mijn WV's' zien" Height="19px" BorderColor="#FF8000"></asp:Button>47 <asp:Button style="LEFT: 495px; CURSOR: hand; FONT-FAMILY: 'Lucida Sans'; POSITION: relative; TOP: -21px" id="Button2" runat="server" Text="Reset filters" Font-Size="8pt" Font-Bold="True" BorderStyle="Ridge" Width="123px" ForeColor="#0000C0" BackColor="#FFC080" ToolTip="Reset alle filters en geef het toaal overzicht weer" BorderColor="#FF8000"></asp:Button>  48 <asp:Button style="BORDER-TOP-WIDTH: thin; BORDER-LEFT-WIDTH: thin; BORDER-LEFT-COLOR: moccasin; BACKGROUND-ATTACHMENT: fixed; LEFT: 183px; BACKGROUND-IMAGE: url(http://eb-service/WV/MemberPaginas/images/vraagteken.gif); BORDER-BOTTOM-WIDTH: thin; BORDER-BOTTOM-COLOR: moccasin; CURSOR: hand; BORDER-TOP-COLOR: moccasin; BACKGROUND-REPEAT: no-repeat; POSITION: relative; TOP: -17px; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: thin; BORDER-RIGHT-COLOR: moccasin" id="Button_help4" runat="server" Font-Size="8pt" BorderStyle="None" Width="21px" Height="24px" BorderColor="#FFE0C0" tooltip="info..."></asp:Button>49 <asp:Button style="BORDER-TOP-WIDTH: thin; BORDER-LEFT-WIDTH: thin; BORDER-LEFT-COLOR: moccasin; BACKGROUND-ATTACHMENT: fixed; LEFT: -240px; BACKGROUND-IMAGE: url(http://eb-service/WV/MemberPaginas/images/vraagteken.gif); BORDER-BOTTOM-WIDTH: thin; BORDER-BOTTOM-COLOR: moccasin; CURSOR: hand; BORDER-TOP-COLOR: moccasin; BACKGROUND-REPEAT: no-repeat; POSITION: relative; TOP: -18px; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: thin; BORDER-RIGHT-COLOR: moccasin" id="Button_help5" runat="server" Font-Size="8pt" BorderStyle="None" Width="21px" Height="24px" BorderColor="#FFE0C0" tooltip="info..."></asp:Button>50 <asp:Button style="BORDER-TOP-WIDTH: thin; BORDER-LEFT-WIDTH: thin; BORDER-LEFT-COLOR: moccasin; BACKGROUND-ATTACHMENT: fixed; LEFT: 106px; BACKGROUND-IMAGE: url(http://eb-service/WV/MemberPaginas/images/vraagteken.gif); BORDER-BOTTOM-WIDTH: thin; BORDER-BOTTOM-COLOR: moccasin; CURSOR: hand; BORDER-TOP-COLOR: moccasin; BACKGROUND-REPEAT: no-repeat; POSITION: relative; TOP: 20px; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: thin; BORDER-RIGHT-COLOR: moccasin" id="Button_help6" runat="server" Font-Size="8pt" BorderStyle="None" Width="21px" Height="24px" BorderColor="#FFE0C0" tooltip="info..."></asp:Button> <BR />51 <asp:DropDownList style="LEFT: 1px; CURSOR: hand; POSITION: relative; TOP: -7px" id="DDL_nummer" runat="server" Font-Size="9pt" Width="87px" ToolTip="Filter: geeft alleen de geselecteerde WV weer" AutoPostBack="True" DataSourceID="SqlDataSource2" AppendDataBoundItems="True" DataTextField="Kop1AlgVpnummer" DataValueField="Kop1AlgVpnummer">52 <asp:ListItem Value="0">geen filter</asp:ListItem>53 </asp:DropDownList>54 <asp:DropDownList style="LEFT: 18px; CURSOR: hand; POSITION: relative; TOP: -7px" id="DDL_aanvrager" runat="server" Font-Size="8pt" Width="133px" ToolTip="Filter: geeft alleen de WV's met de geselecteerde aanvrager weer" AutoPostBack="True" DataSourceID="SqlDataSource3" AppendDataBoundItems="True" DataTextField="Achternaam" DataValueField="asp_naam">55 <asp:ListItem Selected="True" Value="0">geen filter</asp:ListItem>56 </asp:DropDownList>57 <asp:TextBox style="LEFT: 50px; CURSOR: text; POSITION: relative; TOP: -9px" id="LokatieTextBox" runat="server" Font-Size="8pt" Width="112px" ToolTip="Filter: geeft alleen de WV's weer waarin zoekterm voor komt (veld: locatie)"></asp:TextBox>58 <asp:Button style="BORDER-TOP-WIDTH: thin; BORDER-LEFT-WIDTH: thin; BORDER-LEFT-COLOR: background; BACKGROUND: url(http://eb-service/WV/MemberPaginas/images/oogjes.gif) yellow fixed repeat-y center center; LEFT: 118px; BORDER-BOTTOM-WIDTH: thin; BORDER-BOTTOM-COLOR: background; OVERFLOW: hidden; CURSOR: hand; BORDER-TOP-COLOR: background; POSITION: relative; TOP: -4px; BORDER-RIGHT-WIDTH: thin; BORDER-RIGHT-COLOR: background" id="zoek1Button" onclick="zoek1" runat="server" Width="38px" Height="21px" tooltip="Zoek!"></asp:Button>59 <asp:Button style="LEFT: 7px; CURSOR: hand; POSITION: relative; TOP: -9px" id="Button1" runat="server" Text="reset" Font-Size="7pt" Font-Bold="True" ForeColor="#FF0000" ToolTip="Reset locatiefilter + overzicht"></asp:Button>60 <asp:TextBox style="LEFT: 123px; CURSOR: text; POSITION: relative; TOP: -8px" id="RedenTextBox" runat="server" Font-Size="8pt" Width="139px" ToolTip="Filter: geeft alleen de WV's weer waarin zoekterm voor komt (veld: Werk/reden)"></asp:TextBox>61 <asp:Button style="LEFT: 121px; CURSOR: hand; POSITION: relative; TOP: -9px" id="Button8" runat="server" Text="reset" Font-Size="7pt" Font-Bold="True" ForeColor="#FF0000" ToolTip="Reset werk/reden-filter + overzicht"></asp:Button>62 <asp:Label style="LEFT: -190px; POSITION: relative; TOP: 22px; TEXT-ALIGN: right" id="AantalLabel" runat="server" Font-Size="12pt" Font-Bold="True" Width="151px" ForeColor="#FF0033" BackColor="#0000CC"></asp:Label>63 <asp:DropDownList style="LEFT: -313px; CURSOR: hand; POSITION: relative; TOP: -40px" id="JaarDropDownList" runat="server" Font-Size="9pt" Width="84px" ForeColor="Yellow" BackColor="Red" ToolTip="Filter: geeft alleen de WV's met het geselecteerde jaar weer" AutoPostBack="True">64 <asp:ListItem Value="0">Geen filter</asp:ListItem>65 <asp:ListItem Value="1">2006</asp:ListItem>66 <asp:ListItem Value="2">2007</asp:ListItem>67 </asp:DropDownList>68 <asp:DropDownList style="LEFT: 61px; CURSOR: hand; POSITION: relative; TOP: -5px" id="DDL_status" runat="server" Font-Size="9pt" Width="56px" ToolTip="Filter: geeft alleen de WV's met de geselecteerde status weer" AutoPostBack="True">69 <asp:ListItem Value="0">= 0</asp:ListItem>70 <asp:ListItem Value="1">= 1</asp:ListItem>71 <asp:ListItem Value="2"><= 1</asp:ListItem>72 <asp:ListItem Value="3">= 2</asp:ListItem>73 <asp:ListItem Value="4"><= 2</asp:ListItem>74 <asp:ListItem Value="5">= 3</asp:ListItem>75 <asp:ListItem Value="6"><= 3</asp:ListItem>76 <asp:ListItem Value="7">= 4</asp:ListItem>77 <asp:ListItem Value="8"><= 4</asp:ListItem>78 <asp:ListItem Value="9">= 5</asp:ListItem>79 <asp:ListItem Value="10"><= 5</asp:ListItem>80 </asp:DropDownList>81 <asp:Button style="BORDER-TOP-WIDTH: thin; BORDER-LEFT-WIDTH: thin; BORDER-LEFT-COLOR: moccasin; BACKGROUND-ATTACHMENT: fixed; LEFT: 60px; BACKGROUND-IMAGE: url(http://eb-service/WV/MemberPaginas/images/vraagteken.gif); BORDER-BOTTOM-WIDTH: thin; BORDER-BOTTOM-COLOR: moccasin; CURSOR: hand; BORDER-TOP-COLOR: moccasin; BACKGROUND-REPEAT: no-repeat; POSITION: relative; TOP: -5px; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: thin; BORDER-RIGHT-COLOR: moccasin" id="Button_help" runat="server" Font-Size="8pt" BorderStyle="None" Width="21px" Height="24px" BorderColor="#FFE0C0" tooltip="info..."></asp:Button>82 <asp:Button style="BORDER-TOP-WIDTH: thin; BORDER-LEFT-WIDTH: thin; BORDER-LEFT-COLOR: moccasin; BACKGROUND-ATTACHMENT: fixed; LEFT: -690px; BACKGROUND-IMAGE: url(http://eb-service/WV/MemberPaginas/images/vraagteken.gif); BORDER-BOTTOM-WIDTH: thin; BORDER-BOTTOM-COLOR: moccasin; CURSOR: hand; BORDER-TOP-COLOR: moccasin; BACKGROUND-REPEAT: no-repeat; POSITION: relative; TOP: -5px; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: thin; BORDER-RIGHT-COLOR: moccasin" id="Button_help2" runat="server" Font-Size="8pt" BorderStyle="None" Width="21px" Height="23px" BorderColor="#FFE0C0" tooltip="info..."></asp:Button>83 <asp:Button style="BORDER-TOP-WIDTH: thin; BORDER-LEFT-WIDTH: thin; BORDER-LEFT-COLOR: moccasin; BACKGROUND-ATTACHMENT: fixed; LEFT: -866px; BACKGROUND-IMAGE: url(http://eb-service/WV/MemberPaginas/images/vraagteken.gif); BORDER-BOTTOM-WIDTH: thin; BORDER-BOTTOM-COLOR: moccasin; CURSOR: hand; BORDER-TOP-COLOR: moccasin; BACKGROUND-REPEAT: no-repeat; POSITION: relative; TOP: -6px; BACKGROUND-COLOR: transparent; BORDER-RIGHT-WIDTH: thin; BORDER-RIGHT-COLOR: moccasin" id="Button_help3" runat="server" Font-Size="8pt" BorderStyle="None" Width="21px" Height="24px" BorderColor="#FFE0C0" tooltip="info..."></asp:Button>84 <asp:GridView id="GridView1" runat="server" BorderWidth="1px" BorderStyle="Groove" Width="1000px" ForeColor="Black" BackColor="PapayaWhip" AutoGenerateColumns="False" DataKeyNames="Kop1AlgVpnummer" PageSize="8" AllowPaging="True" BorderColor="Tan" AllowSorting="True" CellPadding="2" EmptyDataText="Geen data!" OnPageIndexChanging="GridView1_PageIndexChanging" OnSorting="GridView1_Sorting">85 <PagerSettings PageButtonCount="30" Mode="NumericFirstLast"></PagerSettings>86 <FooterStyle BackColor="Tan"></FooterStyle>87 <Columns>88 <asp:TemplateField SortExpression="Kop1AlgVpnummer" HeaderText="WV:">89 <ItemStyle BackColor="SandyBrown" Width="60px" HorizontalAlign="Center" Font-Bold="True"></ItemStyle>90 <ItemTemplate>91 <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Kop1AlgVpnummer", "details.aspx?WVnummer={0}")%>'92 Text='<%# Eval("Kop1AlgVpnummer")%>' ToolTip='<%# Eval("titel")%>'></asp:HyperLink>93 <br />94 <asp:Button ID="Button7" runat="server" CommandArgument='<%# Eval("Kop1AlgVpnummer")%>'95 Font-Bold="True" Font-Size="7pt" ForeColor="Red" Height="15px" OnCommand="pdf_maak"96 Style="font-family: 'Lucida Sans'" Text="PDF" Width="30px" />97 </ItemTemplate>98 </asp:TemplateField>99 <asp:TemplateField SortExpression="Kop1VpPlus" HeaderText="WV-Plus">100 <ItemStyle Width="40px" HorizontalAlign="Center"></ItemStyle>101 <ItemTemplate>102 <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Kop1VpPlus")%>' Enabled="false" />103 </ItemTemplate>104 </asp:TemplateField>105 <asp:TemplateField SortExpression="Kop1AanvraagNaam" HeaderText="Aanvrager">106 <ItemStyle Width="95px" HorizontalAlign="Left"></ItemStyle>107 <ItemTemplate>108 <asp:Label ID="Label2" runat="server" Text='<%# Bind("Kop1AanvraagNaam")%>'></asp:Label>109 </ItemTemplate>110 </asp:TemplateField>111 <asp:TemplateField SortExpression="Kop1AanvraagDatum" HeaderText="Aanvraag-datum">112 <ItemStyle Width="80px" HorizontalAlign="Left"></ItemStyle>113 <ItemTemplate>114 <asp:Label ID="Label3" runat="server" Text='<%# Bind("Kop1AanvraagDatum", "{0:d}")%>'></asp:Label><br />115 </ItemTemplate>116 </asp:TemplateField>117 <asp:TemplateField SortExpression="Kop1AlgLocatie" HeaderText="Locatie">118 <ItemStyle Width="130px" HorizontalAlign="Left"></ItemStyle>119 <ItemTemplate>120 <asp:Label ID="Label4" runat="server" Text='<%# Bind("Kop1AlgLocatie")%>'></asp:Label>121 </ItemTemplate>122 </asp:TemplateField>123 <asp:TemplateField HeaderText="Werk / Reden">124 <ItemStyle Height="60px" Wrap="True" HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle>125 <ItemTemplate>126 <asp:Panel ID="Panel2" runat="server" Height="60px" ScrollBars="Vertical">127 <asp:Label ID="Label5" runat="server" Height="60px" Text='<%# Bind("Kop2WerkReden")%>'></asp:Label>128 </asp:Panel>129 </ItemTemplate>130 </asp:TemplateField>131 <asp:TemplateField SortExpression="Kop1UitvAanvangsdatum1" HeaderText="Aanvangs-datum">132 <ItemStyle Width="80px" HorizontalAlign="Left"></ItemStyle>133 <ItemTemplate>134 <asp:Label ID="Label1" runat="server" Text='<%# Eval("Kop1UitvAanvangsdatum1", "{0:d}")%>' ToolTip="aanvangsdatum"></asp:Label> <br />135 <asp:Label ID="Label7" runat="server" Style="font-size: 8pt; color: blue; font-style: italic;136 background-color: yellow" Text='<%# Eval("Kop1UitvEinddatum1", "{0:d}")%>' ToolTip="einddatum"></asp:Label>137 </ItemTemplate>138 </asp:TemplateField>139 <asp:TemplateField SortExpression="status" HeaderText="Status">140 <ItemStyle Width="40px" HorizontalAlign="Center"></ItemStyle>141 <ItemTemplate>142 <asp:Label ID="Label6" runat="server" Text='<%# Bind("status")%>'></asp:Label>143 </ItemTemplate>144 </asp:TemplateField>145 <asp:TemplateField Visible="False" ShowHeader="False">146 <ItemStyle Width="35px" HorizontalAlign="Left"></ItemStyle>147 <ItemTemplate>148 <asp:Button ID="Button3" runat="server" Style="background-attachment: fixed; background-color: transparent;149 background-image: url(http://eb-service/WV/MemberPaginas/images/delete.gif); background-repeat:no-repeat ; border-top-width: thin; border-left-width: thin; border-left-color: moccasin; border-bottom-width: thin; border-bottom-color: moccasin; border-top-color: moccasin; border-right-width: thin; border-right-color: moccasin;"150 Width="32px" tooltip="Verwijder WV (definitief!!!!!)" CommandArgument='<%# eval("Kop1AlgVpNummer")%>' Height="30px" OnCommand="Button3_Command" BorderColor="#FFE0C0" BorderStyle="None" />151 <ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="Button3" ConfirmText="Zeker weten?"></ajaxToolkit:ConfirmButtonExtender>152 </ItemTemplate>153 </asp:TemplateField>154 </Columns>155156 <RowStyle Font-Size="11pt" Font-Overline="False"></RowStyle>157 <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite"></SelectedRowStyle>158 <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" Font-Size="10pt" Font-Bold="True" Font-Strikeout="False"></PagerStyle>159 <HeaderStyle BackColor="Tan" Font-Size="12pt" Font-Overline="False" Font-Bold="True"></HeaderStyle>160 <AlternatingRowStyle BackColor="Moccasin" Font-Size="11pt" Font-Strikeout="False"></AlternatingRowStyle>161 </asp:GridView>162 <asp:Button style="LEFT: 950px; CURSOR: hand; POSITION: absolute; TOP: 68px" id="Button5" runat="server" Text="delete" Font-Size="8pt" Font-Bold="True" BorderStyle="Ridge" ForeColor="#0000C0" BackColor="#FFC080" ToolTip="laat kolom 'verwijderen' zien (alleen beheerders)" Height="19px" BorderColor="#FF8000"></asp:Button>163164 <asp:Panel id="Panel1" runat="server" Width="1000px" HorizontalAlign="Center" Direction="LeftToRight">165 <asp:SqlDataSource id="SqlDataSource2" runat="server" SelectCommand="SELECT [Kop1AlgVpnummer] FROM [DATA] ORDER BY [Kop1AlgVpnummer] DESC" ConnectionString="<%$ ConnectionStrings:WV-ConnectionString%>">166 </asp:SqlDataSource>167 <asp:SqlDataSource id="SqlDataSource3" runat="server" SelectCommand="SELECT [achternaam], [asp_naam] FROM [emailadressen] WHERE ([achternaam] IS NOT NULL) ORDER BY [achternaam]" ConnectionString="<%$ ConnectionStrings:WV-ConnectionString%>">168 </asp:SqlDataSource>169170 <asp:UpdateProgress id="UpdateProgress1" runat="server">171 <ProgressTemplate>172 <div style="left: 280px; position: absolute; top: 400px">173 <img alt="" src="../MemberPaginas/images/progressbar_long_green.gif" height="40px" width="500px" />174 </div>175 </ProgressTemplate>176 </asp:UpdateProgress>177178 <ajaxToolkit:TextBoxWatermarkExtender id="TextBoxWatermarkExtender1" watermarkText="Filter: werk/reden" runat="server" WatermarkCssClass="watermerk" TargetControlID="RedenTextBox"></ajaxToolkit:TextBoxWatermarkExtender>179 <ajaxToolkit:TextBoxWatermarkExtender id="TextBoxWatermarkExtender2" watermarkText="Filter: locatie" runat="server" WatermarkCssClass="watermerk" TargetControlID="LokatieTextBox"></ajaxToolkit:TextBoxWatermarkExtender>180 <asp:Panel style="BORDER-RIGHT: green thin solid; BORDER-TOP: green thin solid; DISPLAY: none; BORDER-LEFT: green thin solid; COLOR: blue; BORDER-BOTTOM: green thin solid; BACKGROUND-COLOR: yellow; TEXT-ALIGN: left; backcolor: gray; forecolor: blue" id="Panel10" runat="server" Font-Size="10pt" Width="350px"><P><SPAN style="TEXT-DECORATION: underline">Met dit filter kunt u het overzicht filteren aan de hand van de gewenste status:</SPAN></P>0: aangevraagd<BR />1: niet akkoord<BR />2: akkoord, nog niet actief<BR />3: actief<BR />4: verlopen<BR />5: beeindigd<BR /><BR />Het is mogelijk om alleen te filteren op WV's met een bepaalde status (=), of op WV's met een bepaalde status en kleiner (<=).<BR /><BR />Dit filter staat standaard op alleen actieve WV's ingesteld (status = 3).<BR /><BR />Let op, dit filter werkt samen met de andere filters!<BR /><BR /><DIV style="TEXT-ALIGN: center"><asp:Button id="OkButton" runat="server" Text="OK"></asp:Button></DIV></asp:Panel>181 <asp:Panel style="BORDER-RIGHT: green thin solid; BORDER-TOP: green thin solid; DISPLAY: none; BORDER-LEFT: green thin solid; COLOR: blue; BORDER-BOTTOM: green thin solid; BACKGROUND-COLOR: yellow; TEXT-ALIGN: left; backcolor: gray; forecolor: blue" id="Panel11" runat="server" Font-Size="10pt" Width="350px"><P><SPAN style="TEXT-DECORATION: underline">Met dit filter kunt u het overzicht filteren op aanvrager.</SPAN></P>Selecteer een naam in de keuzelijst en het overzicht geeft alle WV's weer van die persoon.<BR /><BR />Let op, dit filter werkt samen met de andere filters!<BR /><BR /><DIV style="TEXT-ALIGN: center"><asp:Button id="OkButton2" runat="server" Text="OK"></asp:Button></DIV></asp:Panel>182 <asp:Panel style="BORDER-RIGHT: green thin solid; BORDER-TOP: green thin solid; DISPLAY: none; BORDER-LEFT: green thin solid; COLOR: blue; BORDER-BOTTOM: green thin solid; BACKGROUND-COLOR: yellow; TEXT-ALIGN: left; backcolor: gray; forecolor: blue" id="Panel12" runat="server" Font-Size="10pt" Width="350px"><P><SPAN style="TEXT-DECORATION: underline">Met dit filter kunt u direct een WV selecteren.</SPAN></P>Selecteer een WV in de keuzelijst (alle WV's) en het overzicht geeft alleen die WV weer.<BR /><BR />Let op, dit filter werkt niet samen met de andere filters!<BR /><BR /><DIV style="TEXT-ALIGN: center"><asp:Button id="OkButton3" runat="server" Text="OK"></asp:Button></DIV></asp:Panel>183 <asp:Panel style="BORDER-RIGHT: green thin solid; BORDER-TOP: green thin solid; DISPLAY: none; BORDER-LEFT: green thin solid; COLOR: blue; BORDER-BOTTOM: green thin solid; BACKGROUND-COLOR: yellow; TEXT-ALIGN: left; backcolor: gray; forecolor: blue" id="Panel13" runat="server" Font-Size="10pt" Width="350px"><P><SPAN style="TEXT-DECORATION: underline">Met dit filter kunt u het overzicht filteren op jaar.</SPAN></P>Selecteer een jaar in de keuzelijst en het overzicht geeft alleen WV's weer die op dat jaar betrekking hebben.<BR /><BR />Dit filter staat standaard op het huidige jaar.<BR /><BR />Let op, dit filter werkt samen met de andere filters!<BR /><BR /><DIV style="TEXT-ALIGN: center"><asp:Button id="OkButton4" runat="server" Text="OK"></asp:Button></DIV></asp:Panel>184 <asp:Panel style="BORDER-RIGHT: green thin solid; BORDER-TOP: green thin solid; DISPLAY: none; BORDER-LEFT: green thin solid; COLOR: blue; BORDER-BOTTOM: green thin solid; BACKGROUND-COLOR: yellow; TEXT-ALIGN: left; backcolor: gray; forecolor: blue" id="Panel14" runat="server" Font-Size="10pt" Width="350px"><P><SPAN style="TEXT-DECORATION: underline">Exporteer hiermee het overzicht naar PDF.</SPAN></P>Met deze knop kunt u het huidige overzicht naar een zgn. PDF-bestand exporteren. <BR /><BR /><DIV style="TEXT-ALIGN: center"><asp:Button id="OkButton5" runat="server" Text="OK"></asp:Button></DIV></asp:Panel>185 <asp:Panel style="BORDER-RIGHT: green thin solid; BORDER-TOP: green thin solid; DISPLAY: none; BORDER-LEFT: green thin solid; COLOR: blue; BORDER-BOTTOM: green thin solid; BACKGROUND-COLOR: yellow; TEXT-ALIGN: left; backcolor: gray; forecolor: blue" id="Panel15" runat="server" Font-Size="10pt" Width="350px"><P><SPAN style="TEXT-DECORATION: underline">Voer zoekopdracht uit.</SPAN></P>Met deze knop kunt u het overzicht filteren met de gewenste zoekopties.<BR /><BR />Er zijn meerdere zoekopties aanwezig: de zoekopdracht start automatisch bij het kiezen van een item in keuzelijsten, maar niet bij de tekst-filters (locatie en werk/reden). <BR /><BR />Kies ook deze knop om uw zoekopdracht opnieuw uit te voeren en/of het overzicht te verversen.<BR /><BR /><DIV style="TEXT-ALIGN: center"><asp:Button id="OkButton6" runat="server" Text="OK"></asp:Button></DIV></asp:Panel>186 <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender" runat="server" TargetControlID="Button_help" OkControlID="OkButton" DropShadow="true" BackgroundCssClass="modalBackground" PopupControlID="Panel10"></ajaxToolkit:ModalPopupExtender>187 <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender1" runat="server" TargetControlID="Button_help2" OkControlID="OkButton2" DropShadow="true" BackgroundCssClass="modalBackground" PopupControlID="Panel11"></ajaxToolkit:ModalPopupExtender>188 <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender2" runat="server" TargetControlID="Button_help3" OkControlID="OkButton3" DropShadow="true" BackgroundCssClass="modalBackground" PopupControlID="Panel12"></ajaxToolkit:ModalPopupExtender>189 <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender3" runat="server" TargetControlID="Button_help4" OkControlID="OkButton4" DropShadow="true" BackgroundCssClass="modalBackground" PopupControlID="Panel13"></ajaxToolkit:ModalPopupExtender>190 <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender4" runat="server" TargetControlID="Button_help5" OkControlID="OkButton5" DropShadow="true" BackgroundCssClass="modalBackground" PopupControlID="Panel14"></ajaxToolkit:ModalPopupExtender>191 <ajaxToolkit:ModalPopupExtender id="ModalPopupExtender5" runat="server" TargetControlID="Button_help6" OkControlID="OkButton6" DropShadow="true" BackgroundCssClass="modalBackground" PopupControlID="Panel15"></ajaxToolkit:ModalPopupExtender>192 <asp:Label id="naamLabel" runat="server" Font-Size="6pt" Visible="False"></asp:Label>193 </asp:Panel>194 </ContentTemplate>195 </asp:UpdatePanel>196 </div>197</asp:Content>

Are you sure you need to use the Confirm button? If all you want is for a confirm box to popup with a message, you can try just using the OnClientClick of the button itself. It would look like

onclientclick="return confirm('Zeker weten?')"

so your button will be...

<asp:Button ID="Button3" runat="server" Style="background-attachment: fixed; background-color: transparent;
background-image: url(http://blabla.gif); background-repeat:no-repeat ; border-top-width: thin; border-left-width: thin; border-left-color: moccasin; border-bottom-width: thin; border-bottom-color: moccasin; border-top-color: moccasin; border-right-width: thin; border-right-color: moccasin;"
Width="32px" tooltip="Verwijder WV (definitief!!!!!)" CommandArgument='<%# eval("Kop1AlgVpNummer")%>' Height="30px" OnCommand="Button3_Command" BorderColor="#FFE0C0" BorderStyle="None"onclientclick="return confirm('Zeker weten?')" />

I do this all the time in gridview delete buttons. It works just like the confirm button.

-Alan


Good tip, I'll try this tomorrow. Maybe i didn't think of this because of my limited knowledge of javascript...

This works fine, the error is gone.

You could, however, ask yourself why the error is produced...

ConfirmButtonExtender inside Gridview only fires from the first row

I have a gridview, with more than 1 row and the first column is a template in which I have the normal two command buttons Delete and Cancel. Within this template, I have also put a ConfirmButtonExtender for the Delete button to give the user an extra out.

The problem I am having is that the ConfirmButtonExtender only fires for the first row but it does not show up for the subsequent rows. When I click the Delete button for the second row, delete the row is exactly what it does.. without asking if I want to or not as I had set up.

I am wondering if anyone else had the same problem, couldn't find anything online.

Thanks in advance.

Hi

The following works just fine with me,
each button-click (on each row) triggers the confirm message.

 <asp:TemplateField HeaderText="confirm"><ItemTemplate> <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Button" /> <cc1:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="Button4"> </cc1:ConfirmButtonExtender></ItemTemplate> </asp:TemplateField>

Please try to replicate the behavior you have ina working code example !
Then I can easily look into it!

Kind regards,
Wim

confirmbuttonextender error

I have a page with a user control in it. The user control has a 'delete' button which has a confirmbuttonextender attached to it.

I keep getting this error on the page:

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +233
Microsoft.AtlasControlExtender.ScriptControlWrapper.Page_PreRenderComplete(Object sender, EventArgs e) +110
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +75
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6198

My user control has code blocks to allow dynamically setting of css classes which is required.

Regards,

Andy.

Hi Andy,

Could you provide more information on the problem? The best would be a complete code sample demonstrating the problem you're having. I'm not able to figure out what's going on with just the above.

Thanks,
Ted

Hi Ted,

I have put the required code on our web server at:

http://www.apex-networks.com/files/UserControls.zip

They are all ascx files, and are used in the following heirarchy:

UserMaint.ascx contains one SiteApplicationGridViewCollection.ascx which dynamically creates as many SiteApplicationGridView.ascx as required.

At the moment there is no ConfirmButtonExtender on the delete button in UserMaint.ascx but if you add one you get the error.

Hope this helps.

Andy.

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?

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 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.

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