Nov 16, 2016, 7:32 AM
[CLOSED] Can not access dynamically created asp.net classic controls' values
Hi, in my project as a part of requirements i am creating a little bit complex table. To do that i am using asp.net Table control and creating table dynamically with code below.
I am creating table and adding rows it but when click on ext.net button with direct event, I cannot access the table's rows.
My .aspx page uses a masterpage with resourcemanager(rsm). Rsm's configuration is shown below.
Could you check the code snippets below and what it is wrong with my code to access table's content ?
Version: Ext.net 2.5.2
I am creating table and adding rows it but when click on ext.net button with direct event, I cannot access the table's rows.
My .aspx page uses a masterpage with resourcemanager(rsm). Rsm's configuration is shown below.
Could you check the code snippets below and what it is wrong with my code to access table's content ?
Version: Ext.net 2.5.2
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="shortcut icon" type="image/png" href="/favicon.ico"/>
<title></title>
<style>
.horizontal-menu .x-menu-item-link {
line-height: 20px;
}
.horizontal-menu .x-menu-item-arrow {
display: none;
}
</style>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="rsm" runat="server" AjaxTimeout="120000"
ShowWarningOnAjaxFailure="false" DisableViewState="false">
</ext:ResourceManager>
<ext:Viewport runat="server" ID="vwPortMaster" Layout="BorderLayout">
<Items>
<ext:Panel runat="server" Region="Center" Header="false" Layout="FitLayout" Border="false" AutoScroll="true">
<Content>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</Content>
</ext:Panel>
</Items>
</ext:Viewport>
</form>
</body>
</html>
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="qTest.aspx.cs" Inherits="qTest" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<style type="text/css">
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
font-family: Arial, Helvetica, sans-serif;
font-weight: normal;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<ext:Panel runat="server" ID="p" Title="LIST" AutoScroll="true">
<TopBar>
<ext:Toolbar runat="server" ID="tlb">
<Items>
<ext:Button ID="btnSave" runat="server" Text="SAVE" ViewStateMode="Enabled">
<DirectEvents>
<Click OnEvent="btnSave_Click">
<Confirmation ConfirmRequest="true" Message="Save ?"></Confirmation>
<EventMask ShowMask="true" Msg="Saving..."></EventMask>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:Container ID="Container1" runat="server" AutoScroll="true">
<Content>
<asp:Table runat="server" ID="t" Width="100%">
</asp:Table>
</Content>
</ext:Container>
</Items>
</ext:Panel>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using Ext.Net;
public partial class qtest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.Search();
}
}
private void Search()
{
this.CreateFirstRow();
this.Container1.Render();
}
private Random rnd = new Random();
private void CreateFirstRow()
{
TableHeaderRow tr = new TableHeaderRow();
TableHeaderCell hc = new TableHeaderCell();
hc.Text = @"ITEMS";
hc.ColumnSpan = 3;
hc.Width = new Unit(250, UnitType.Pixel);
tr.Cells.Add(hc);
//TdfManager tm = new TdfManager();
//DataTable dtCust = tm.GET_TDF_CustList(1);
//DataTable dt = tm.GET_TDF_By_Id(1);
DataTable dtCust = new DataTable();
dtCust.Columns.Add("cust");
dtCust.Columns.Add("custId");
DataRow dr1 = dtCust.NewRow();
dr1[0] = "Cust1";
dr1[1] = "1";
dtCust.Rows.Add(dr1);
DataRow dr2 = dtCust.NewRow();
dr2[0] = "Cust2";
dr2[1] = "2";
dtCust.Rows.Add(dr2);
DataRow dr3 = dtCust.NewRow();
dr3[0] = "Cust3";
dr3[1] = "3";
dtCust.Rows.Add(dr3);
foreach (DataRow dr in dtCust.Rows)
{
string cust = dr[0].ToString();
string custId = dr[1].ToString();
TableHeaderCell hc2 = new TableHeaderCell();
hc2.Text = cust;
hc2.ID = custId;
hc2.ColumnSpan = 6;
Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
hc2.BackColor = randomColor;
hc2.Width = new Unit(150, UnitType.Pixel);
tr.Cells.Add(hc2);
}
t.Rows.Add(tr);
}
protected void btnSave_Click(object o, DirectEventArgs e)
{
int x = t.Rows.Count;
if(x == 0)
{
Ext.Net.MessageBox msgBox = new MessageBox();
msgBox.Configure(new MessageBoxConfig()
{
Title = "ERROR",
Message = "No rows found",
Icon = MessageBox.Icon.ERROR,
Buttons = MessageBox.Button.OK
});
msgBox.Show();
}
}
}
Last edited by fabricio.murta; Jan 03, 2017 at 9:57 PM.
Reason: no user feedback for 7+ days