Question : Asp.net ajax error. the same if 'mdPopup' cannot be added to the application.

the same if 'mdPopup' cannot be added to the application.
see image
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ctrlMyMail.ascx.cs"
    Inherits="OmegaLove.Web.UI.ctrlMyMail" %>
<%@ Register Assembly="System.Web.Ajax" Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<script type="text/javascript">
    function SelectAll(id) {
        var frm = document.forms[0];
        for (i = 0; i < frm.elements.length; i++) {
            if (frm.elements[i].type == "checkbox") {
                frm.elements[i].checked = document.getElementById(id).checked;
            }
        }
    }  
</script>

<style>
    .modalBackground
    {
        background-color: Gray;
        filter: alpha(opacity=70);
        opacity: 0.7;
    }
    .confirm
    {
        background-color: White;
        border-style: solid;
        border-color: Red;
        padding: 10px;
        width: 400px;
        font-family: Arial;
        font-size: 11px;
    }
    .confirmtable
    {
        background-color: White;
        border-style: none;
        border-color: Silver;
        padding: 0px;
        width: 400px;
        font-family: Arial;
        font-size: 11px;
    }
    .confirmbutton
    {
        font-family: Arial;
        font-size: 11px;
    }
</style>
<div class="disignBoxFirst">
    <div class="boxFirstHeader">
        <div class="boxContent">
            <div id="profile_details_wrapper">
                <br />
                <div class="pad_cont" style="margin: 10;">
                    <div class="pad_box2">
                        <div class="h2 t_sprite mail_send" style="float: right;">
                            <a href="#">Sent Messages</a></div>
                        <div class="h1 t_sprite mail">
                            Messages Inbox</div>
                        <asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>
                                <asp:GridView ID="gvInbox" runat="server" DataKeyNames="messageid" GridLines="None"
                                    OnPageIndexChanging="gvInbox_PageIndexChanging" OnRowDataBound="gvInbox_RowDataBound"
                                    Height="20px" HorizontalAlign="Center" VerticalAlign="Middle" AllowPaging="true"
                                    AllowSorting="true" EmptyDataText="No data available." PageSize="5" AutoGenerateColumns="false"
                                    CssClass="customers-grid" OnRowCreated="gvInbox_RowCreated">
                                    <AlternatingRowStyle Height="25px" HorizontalAlign="Center" VerticalAlign="Middle" />
                                    <Columns>
                                        <asp:TemplateField HeaderText="CheckAll">
                                            <HeaderStyle CssClass="delete-member"></HeaderStyle>
                                            <ItemStyle CssClass="delete-member" Wrap="False"></ItemStyle>
                                            <HeaderTemplate>
                                                <asp:CheckBox ID="chkSelectAll" runat="server" CausesValidation="True" Text="" OnCheckedChanged="chkSelectAll_CheckedChanged" />
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkSelect" runat="server" OnCheckedChanged="chkSelect_CheckedChanged" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField>
                                            <HeaderStyle CssClass="from-pic"></HeaderStyle>
                                            <ItemStyle CssClass="from-pic" Wrap="False"></ItemStyle>
                                            <ItemTemplate>
                                                <a id="HLMainPicID" runat="server" navigateurl='<%#"~/Secure/ViewProfile.aspx?UserName="+Eval("FromUsername") %>'>
                                                    <asp:Image ID="MainPicID" BorderWidth="2" BorderColor="Silver" Style="vertical-align: middle"
                                                        class="srpic" runat="server" />
                                                </a>
                                                <asp:HiddenField ID="hiddenImgID" runat="server" Value='<%#DataBinder.Eval(Container,"DataItem.FromProfileID") %>' />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField HeaderText="From" DataField="FromUsername" SortExpression="FromUsername"
                                            HeaderStyle-CssClass="from-username" ItemStyle-CssClass="from-username" />
                                        <asp:BoundField HeaderText="Subject" DataField="Subject" SortExpression="Subject"
                                            HeaderStyle-CssClass="subject" ItemStyle-CssClass="subject" />
                                        <asp:BoundField HeaderText="Date Sent" DataField="MsgDate" SortExpression="MsgDate"
                                            HtmlEncode="False" DataFormatString="{0:F}" HeaderStyle-CssClass="date-sent"
                                            ItemStyle-CssClass="date-sent" />
                                        <asp:BoundField HeaderText="Read" DataField="MsgRead" SortExpression="MsgRead" HeaderStyle-CssClass="read"
                                            DataFormatString="{0:Yes/No}" ItemStyle-CssClass="read" />
                                        <asp:BoundField HeaderText="Replied" DataField="MsgReplied" SortExpression="MsgReplied"
                                            DataFormatString="{0:Yes/No}" HeaderStyle-CssClass="replied" ItemStyle-CssClass="replied" />
                                    </Columns>
                                </asp:GridView>
                                <asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" OnClientClick="showConfirm(this); return false;"
                                    Text="delete selected" />
                                <br />
                                <br />
                                <br />
                                <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"
                                    BehaviorID="mdlPopup" CancelControlID="btnNo" DropShadow="True" OkControlID="btnOk"
                                    OnCancelScript="cancelClick();" OnOkScript="okClick();" PopupControlID="divDeleteItem"
                                    TargetControlID="divDeleteItem" />
                                <div id="divDeleteItem" runat="server" align="center" class="confirm" style="display: none">
                                    <table align="center" class="confirmtable">
                                        <tr>
                                            <td>
                                                <img align="middle" src="images/warning.jpg" />
                                            </td>
                                            <td>
                                                Are you sure you want to delete selected item(s)?&nbsp;
                                            </td>
                                            <td>
                                                <asp:Button ID="btnOk" runat="server" Text="Yes" class="confirmbutton" />
                                            </td>
                                            <td>
                                                <asp:Button ID="btnNo" runat="server" Text="No" class="confirmbutton" />
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        <div class="clear">
                        </div>
                        <br />
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //  keeps track of the delete button for the row  that is going to be removed
    var _source;
    // keep track of the popup div
    var _popup;

    function showConfirm(source) {
        this._source = source;
        this._popup = $find('mdlPopup');
        //  find the confirm ModalPopup and show it    
        this._popup.show();
    }

    function okClick() {
        //  find the confirm ModalPopup and hide it    
        this._popup.hide();
        //  use the cached button as the postback source
        __doPostBack(this._source.name, '');
    }

    function cancelClick() {
        //  find the confirm ModalPopup and hide it 
        this._popup.hide();
        //  clear the event source
        this._source = null;
        this._popup = null;
    }
</script>

---------------------
code behind
public static string ConnnectionString = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
        string message = string.Empty;
        DataSet ds = null;
        DataTable dt = null;
        private static string mstrConn = String.Empty;
        private static string UserId = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!(HttpContext.Current.User.Identity.IsAuthenticated))
            //    Response.Redirect("~/Login.aspx");
            UserId = HttpContext.Current.User.Identity.Name;
            if (!IsPostBack)
            {
                if (UserId != null)
                {
                    PopulateMailbox("", "");
                }
                else
                {
                    Response.Redirect("~/Login.aspx");
                }
            }

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in gvInbox.Rows)
            {
                CheckBox chkDelete = (CheckBox)row.FindControl("chkSelect");
                if (chkDelete.Checked)
                {
                    int returnValue = 0;
                    try
                    {
                        tbl_Mailbox tbl_Mailbox = new tbl_Mailbox();
                        tbl_Mailbox.MessageID = (int)gvInbox.DataKeys[row.RowIndex].Value;

                        returnValue = DataBase.prc_Message_Delete.Execute(ConnnectionString, tbl_Mailbox);
                        if (returnValue == 0) // refresh gridview
                        {
                            PopulateMailbox("", "");
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }

        }

        private void PopulateMailbox(string SortExpression, string DeleteString)
        {
            int intGetProfileID = 0;
            if (UserId == null)
                UserId = HttpContext.Current.User.Identity.Name;

            dt = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, UserId);

            intGetProfileID = Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString());

            try
            {

                ds = DataBase.Procedures.prc_Messages_Select.ToDataSet(ConnnectionString, Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString()), UserId, DeleteString);

                if ((ds != null) && (ds.Tables[0] != null) && (ds.Tables[0].Rows.Count > 0))
                {
                    //LABEL_NoMessages.Text = string.Empty;
                    gvInbox.AllowPaging = true;
                    gvInbox.PageSize = 5;
                    //gvInbox.PagerStyle.Mode = PagerMode.NumericPages;
                    // Add filter for inbox, drafts, etc.
                    //gvInbox.DataSource.DefaultView.RowFilter = String.Concat("Station = \'", sStation, "\'");
                    gvInbox.DataSource = ds.Tables[0].DefaultView;
                    gvInbox.Visible = true;
                    gvInbox.DataBind();
                    
                }
                else
                {
                    gvInbox.Visible = false;
                    //LABEL_NoMessages.Text = "No Messages";
                }

                return;
            }
            catch (SqlException e)
            {
                WebMsgBox.Show(e.ToString());
            }
        }




        protected void gvInbox_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void gvInbox_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                // Add attribute for onclick event on check box in header passing MessageId of Select All checkbox 
                ((CheckBox)e.Row.FindControl("chkSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("chkSelectAll")).ClientID + "')");
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E8EEFA';");
                if (e.Row.RowIndex % 2 == 0)
                { // even
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';");
                } // odd
                else
                {
                    //e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#DEE4E7';");
                }

                HiddenField hdimageId = (HiddenField)e.Row.FindControl("hiddenImgID");

                System.Web.UI.WebControls.Image MainPicID = (System.Web.UI.WebControls.Image)(e.Row.FindControl("MainPicID"));

                MainPicID.ID = hdimageId.Value;
                MainPicID.ToolTip = "Thumbnail of Photo Number =" + hdimageId.Value;


                DataTable dtPhotos = new DataTable();
                dtPhotos = DataBase.Procedures.prc_Photos_Select_Primary.ToDataTable(ConnnectionString, Convert.ToInt32(hdimageId.Value));

                // Get img id from datatable.
                if (((dtPhotos != null) && (dtPhotos.Rows.Count > 0)))
                {
                    if (Convert.ToBoolean(dtPhotos.Rows[0]["p_Primary"]))
                    {
                        MainPicID.ImageUrl = "~/Secure/ShowThumbnail.ashx?img_id=" + dtPhotos.Rows[0]["PhotoID"].ToString() + "&" + "imagesize=T" + "&" + "imageisprimary=" + "True" + "'";
                    }

                }
                else
                {

                    // set default image
                }

            }

        }


        protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkAll = (CheckBox)gvInbox.HeaderRow.FindControl("chkSelectAll");
            if (chkAll.Checked == true)
            {
                foreach (GridViewRow gvRow in gvInbox.Rows)
                {
                    CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
                    chkSel.Checked = true;
                }
            }
            else
            {
                foreach (GridViewRow gvRow in gvInbox.Rows)
                {
                    CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
                    chkSel.Checked = false;
                }
            }
        }

        protected void chkSelect_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkTest = (CheckBox)sender;
            GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
        }

        public static string GetConnectionString(string _connectionStringsName)
        {
            System.Configuration.ConnectionStringSettingsCollection config = System.Configuration.ConfigurationManager.ConnectionStrings;
            for (int i = 0; i < config.Count; i++)
            {
                if (config[i].Name.Equals(_connectionStringsName, StringComparison.OrdinalIgnoreCase))
                    return config[i].ToString();
            }
            return String.Empty;
        }
Attachments:

Answer : Asp.net ajax error. the same if 'mdPopup' cannot be added to the application.

Easyest way with jquery : http://tablesorter.com/docs/

if you need help implementing don't hesitate
Random Solutions  
 
programming4us programming4us