Modalpopupextender funciona, pero el mismo código puesto en clase no funciona
Frecuentes
Visto 435 veces
0
I have the following code that i tested and it works perfect:
Predeterminado2.aspx.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i < 5; i++)
{
var temp = i;
DataTable table = GetTable();
HttpContext.Current.Session[i.ToString()] = table;
GridView gv = new GridView();
gv.ID = "GridView-" + i.ToString();
gv.DataSource = HttpContext.Current.Session[i.ToString()];
gv.DataBind();
Button btn = new Button();
btn.ID = "button-" + i.ToString();
btn.Click += (senders, es) => CreateModalPop(temp,PlaceHolder1, btn.ID);
PlaceHolder1.Controls.Add(gv);
PlaceHolder1.Controls.Add(btn);
}
}
static DataTable GetTable()
{
//
// Here we create a DataTable with four columns.
//
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
//
// Here we add five DataRows.
//
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
return table;
}
protected void CreateModalPop(int num, PlaceHolder ph, string btnID)
{
GridView gv = new GridView();
gv.ID = "GridViewNew-" + num.ToString();
gv.AutoGenerateColumns = true;
gv.DataSource = HttpContext.Current.Session[num.ToString()];
gv.DataBind();
Panel pn = new Panel();
pn.ID = "Panel-" + num.ToString();
pn.CssClass = "modalPopup";
pn.Controls.Add(gv);
AjaxControlToolkit.ModalPopupExtender modalPop = new AjaxControlToolkit.ModalPopupExtender();
modalPop.ID = "ModalPopup-1";
modalPop.PopupControlID = pn.ID;
modalPop.TargetControlID = btnID;
modalPop.BackgroundCssClass = "modalBackground";
// Adding modalpop to panel
pn.Controls.Add(modalPop);
// Adding Panel to placeholder
ph.Controls.Add(pn);
modalPop.Show();
}
}
Predeterminado2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modalBackground { background-color: Gray; filter: alpha(opacity=70); opacity: 0.7; cursor:not-allowed; position: absolute; top: 0%; left: 0%; width: 100%; height: 140%; overflow:hidden;}
.modalPopup { background-color: #ffffdd; border-width: 3px; border-style: solid; border-color: Gray; padding: 3px; width: 350px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager CombineScripts="false" ScriptMode="Release" ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
Now i took this code and tried to put it in a class and use the class instead. After doing that the tables load at first when the page loads, but when you click on one of the buttons it just takes you to a blank page. Why does it do that? or how do i fix it?
Predeterminado3.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modalBackground { background-color: Gray; filter: alpha(opacity=70); opacity: 0.7; cursor:not-allowed; position: absolute; top: 0%; left: 0%; width: 100%; height: 140%; overflow:hidden;}
.modalPopup { background-color: #ffffdd; border-width: 3px; border-style: solid; border-color: Gray; padding: 3px; width: 350px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager CombineScripts="false" ScriptMode="Release" ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
Predeterminado3.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3 : System.Web.UI.Page
{
// Global Object initializer
Class1 inv = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
inv.SetInitialRow(PlaceHolder1);
}
}
}
Clase1.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public void SetInitialRow(PlaceHolder ph)
{
for (int i = 1; i < 5; i++)
{
var temp = i;
DataTable table = GetTable();
HttpContext.Current.Session[i.ToString()] = table;
GridView gv = new GridView();
gv.ID = "GridView-" + i.ToString();
gv.DataSource = HttpContext.Current.Session[i.ToString()];
gv.DataBind();
Button btn = new Button();
btn.ID = "button-" + i.ToString();
btn.Click += (senders, es) => CreateModalPop(temp, ph, btn.ID);
ph.Controls.Add(gv);
ph.Controls.Add(btn);
}
}
static DataTable GetTable()
{
//
// Here we create a DataTable with four columns.
//
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
//
// Here we add five DataRows.
//
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
return table;
}
protected void CreateModalPop(int num, PlaceHolder ph, string btnID)
{
GridView gv = new GridView();
gv.ID = "GridViewNew-" + num.ToString();
gv.AutoGenerateColumns = true;
gv.DataSource = HttpContext.Current.Session[num.ToString()];
gv.DataBind();
Panel pn = new Panel();
pn.ID = "Panel-" + num.ToString();
pn.CssClass = "modalPopup";
pn.Controls.Add(gv);
AjaxControlToolkit.ModalPopupExtender modalPop = new AjaxControlToolkit.ModalPopupExtender();
modalPop.ID = "ModalPopup-1";
modalPop.PopupControlID = pn.ID;
modalPop.TargetControlID = btnID;
modalPop.BackgroundCssClass = "modalBackground";
// Adding modalpop to panel
pn.Controls.Add(modalPop);
// Adding Panel to placeholder
ph.Controls.Add(pn);
modalPop.Show();
}
}
0 Respuestas
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# class modalpopupextender or haz tu propia pregunta.
Start by narrowing down where your problem is. Nobody gets paid to do this, and that looks awful - Jonesopolis
sorry about that, i just figured it would help if i posted all the code, but i guess not, but pretty much my problem is when i use the code with the class, and i click the button that gets created dynamically, it doesn't do anything, it just takes me to a blank page. - Brad Hazelnut