Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
270
grid using ITemplate with ImageButton command only fires after postback
posted

I have a similar example, but for some reason the image button command event I am creating does not fire on the initial page load, it causes a postback, and then after postback it fires correctly. Any help??

<igmisc:WebAsyncRefreshPanel LinkedRefreshControlID="xxx" ID="WebAsyncRefreshPanelControl" runat="server" Width="100%">

<asp:Label ID="lblErr1" runat="server" CssClass="error" />

<center>

<table cellpadding="2" cellspacing="1" border="0" width="725px">

<tr valign="top">

<td>

<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" OnClickCellButton="UltraWebGrid1_OnClickCellButton">

 

<DisplayLayout Name="UltraWebGrid1" AllowSortingDefault="yes" HeaderClickActionDefault="SortSingle"

RowSelectorsDefault="No" SelectTypeRowDefault="Single" SelectTypeCellDefault="Single"

StationaryMargins="Header" TableLayout="Fixed" Version="4.00" />

 

</igtbl:UltraWebGrid>

</td>

<td>

</td>

</tr>

</table>

</center>

<igtxt:WebDateTimeEdit ID="WebDateTimeEdit1" runat="server" DataMode="EditModeText" />

<igcmbo:WebCombo ID="cmbReportSchFrequency" runat="server" Version="4.00" DataValueField="ID" DataTextField="Name" DisplayValue="Name" />

<igcmbo:WebCombo ID="cmbReportDay" runat="server" Version="4.00" DataValueField="ID" DataTextField="Name" DisplayValue="Name" />

</igmisc:WebAsyncRefreshPanel>

private clsSecurity _clsSecurity = null;

ReportSchedules rs;

protected PlaceHolderTemplate pt = null;

private string ErrorMsg = "";

private bool HasUserAndPass = true;

private int iTimeFormat;private void Page_Init(object sender, System.EventArgs e)

{

bool bRedirect = false;

try

{

//Authenticate the user for permission to this pageif (Session["xxx"] == null || Session["xxx"] == null)

{

bRedirect =
true;

}

else

{

{

this.lblErr1.Text = "Sorry, your user name or password is missing. Please contact your onsite manager";

this.lblErr1.Visible = true;

HasUserAndPass = false;

}

int App = _clsSecurity.App(3);if (App <= 0)

{

bRedirect =
true;

}

string sFormat = _clsSecurity.TimeFormat == 0 ? "hh:mm tt" : "HH:mm";

}

}

catch (Exception ex)

{

ErrorMsg =
"UserAuthtication Error: ";

Common.ZLog(System.Web.HttpContext.Current, ErrorMsg, ex);

bRedirect = true;

}

if (bRedirect)

{

Response.Redirect(
"");

}

}

override protected void OnInit(EventArgs e)

{

InitializeComponent();

base.OnInit(e);

}

private void InitializeComponent()

{

this.UltraWebGrid1.InitializeLayout += new Infragistics.WebUI.UltraWebGrid.InitializeLayoutEventHandler(this.UltraWebGrid1_InitializeLayout);this.UltraWebGrid1.TemplatedColumnRestored += new TemplatedColumnRestoredEventHandler(UltraWebGrid1_TemplatedColumnRestored);

}

private void UltraWebGrid1_InitializeLayout(object sender, LayoutEventArgs e)

{

try

{

if (!this.IsPostBack)

{

e.Layout.StationaryMargins =
StationaryMargins.Header;

TemplatedColumn tc = new TemplatedColumn(true);

tc.Key = "Delete";

tc.SortIndicator = SortIndicator.Disabled;

tc.AllowUpdate = AllowUpdate.No;

e.Layout.Bands[0].Columns.Add(tc);

pt =
new PlaceHolderTemplate();

pt.Grid1 = UltraWebGrid1;

tc.CellTemplate = pt;

//Move the delete button to the leftmost column of the grid.

e.Layout.Bands[0].Columns.FromKey("Delete").Move(1);

//Set up the blank new row for inserting a new time entry.

e.Layout.StationaryMargins = StationaryMargins.Header;

e.Layout.RowSelectorsDefault = RowSelectors.No;

e.Layout.RowHeightDefault = new Unit("27px");

//Hide the grid data we do not want to display.

e.Layout.Bands[0].Columns.FromKey("xxx").Hidden = true;

e.Layout.Bands[0].Columns.FromKey("xxx").Hidden = true;

e.Layout.Bands[0].Columns.FromKey("xxx").Hidden = true;

//Set Grid Header titles / Captions.

e.Layout.Bands[0].Columns.FromKey("Delete").Header.Caption = "Del";

e.Layout.Bands[0].Columns.FromKey("xxx").Header.Caption = "Name";

e.Layout.Bands[0].Columns.FromKey("xxx").Header.Caption = "Created";

e.Layout.Bands[0].Columns.FromKey("xxx").Header.Caption = "Last Updated";

e.Layout.Bands[0].Columns.FromKey("xxx").Header.Caption = "Day";

e.Layout.Bands[0].Columns.FromKey("xxx").Header.Caption = "Frequency";

e.Layout.Bands[0].Columns.FromKey("xxx").Header.Caption = "Time";

//Set Column Widths

e.Layout.Bands[0].Columns.FromKey("xxx").Width = new Unit("25px");

e.Layout.Bands[0].Columns.FromKey("xxx").Width = new Unit("150px");

e.Layout.Bands[0].Columns.FromKey("xxx").Width = new Unit("100px");

e.Layout.Bands[0].Columns.FromKey("xxx").Width = new Unit("100px");

e.Layout.Bands[0].Columns.FromKey("xxx").Width = new Unit("80px");

e.Layout.Bands[0].Columns.FromKey("xxx").Width = new Unit("100px");

e.Layout.Bands[0].Columns.FromKey("xxx").Width = new Unit("100px");

e.Layout.Bands[0].Columns.FromKey("xxx").Format = "MM/dd/yyyy";e.Layout.Bands[0].Columns.FromKey("xxx").Format = "MM/dd/yyyy";

}

}

catch (Exception ex)

{

ErrorMsg =
"UltraWebGrid1_InitializeLayout Error: ";Common.ZLog(System.Web.HttpContext.Current, ErrorMsg, ex);

}

}

public class PlaceHolderTemplate : ITemplate

{

public UltraWebGrid Grid1 = null;void ITemplate.InstantiateIn(Control container)

{

CellItem ci = (CellItem)container;

ImageButton ib = new ImageButton();

ib.CssClass = "pointer";ib.ToolTip = "Are you sure you want to delete this report?";ib.ImageUrl = "~/Image/Icon/ico_delete.gif";

ib.CommandArgument = ci.Cell.Row.Index.ToString();

ib.Attributes.Add("onclick", "return confirm ('Delete this record?');");

ib.Command += new CommandEventHandler(ib_Command);ib.EnableViewState = true;

ci.Controls.Add(ib);

}

void ib_Command(object sender, CommandEventArgs e)

{

int Val = Convert.ToInt32(e.CommandArgument);

UltraGridRow currentRow = Grid1.Rows[Val];

string sID = currentRow.Cells.FromKey("ID").Text;

}

}

/// <summary>

/// This method ensures that the delete button is present after page postbacks.

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>void UltraWebGrid1_TemplatedColumnRestored(object sender, ColumnEventArgs e)

{

if (((TemplatedColumn)e.Column).CellTemplate == null)

{

pt =
new PlaceHolderTemplate();

pt.Grid1 = UltraWebGrid1;

((
TemplatedColumn)e.Column).CellTemplate = pt;

}

}

protected void Page_Load(object sender, EventArgs e)

{

try

{

if (_clsSecurity == null) { _clsSecurity = new clsSecurity(Session["xxx"].ToString(), Session["xxx"].ToString()); }if (!IsPostBack)

{

if (HasUserAndPass)

{

Fill_cmbs(cmbReportSchFrequency,
Common.ReportFrequency());Fill_cmbs(cmbReportDay, Common.ReportDay());

iTimeFormat = _clsSecurity.TimeFormat;

string sFormat = iTimeFormat == Common.TIME_FORMAT_STANDARD ? "hh:mm tt" : "HH:mm";

this.WebDateTimeEdit1.DisplayModeFormat = sFormat;this.WebDateTimeEdit1.EditModeFormat = sFormat;

 

LoadGrid();

}

}

}

catch (Exception ex)

{

ErrorMsg =
"Page_Load Error: ";

Common.ZLog(System.Web.HttpContext.Current, ErrorMsg, ex);

Response.Redirect("xxx.aspx");

}

}

private void LoadGrid()

{

if (rs == null) { rs = new ReportSchedules(); };DataSet ds = rs.Get(_clsSecurity.UserRecID.ToString(), _clsSecurity.ClientRecID.ToString());

UltraWebGrid1.DataSource = ds;

UltraWebGrid1.DataBind();

UltraWebGrid1.Columns.Add(
"Edit");

UltraWebGrid1.Columns.FromKey("Edit").Move(0);

UltraWebGrid1.Columns.FromKey("Edit").Key = "Edit";

UltraWebGrid1.Columns.FromKey("Edit").Type = ColumnType.Button;

UltraWebGrid1.Columns.FromKey("Edit").SortIndicator = SortIndicator.Disabled;

UltraWebGrid1.Columns.FromKey("Edit").CellButtonDisplay = CellButtonDisplay.OnMouseEnter;

UltraWebGrid1.Columns.FromKey("Edit").CellButtonStyle.BackColor = Color.Transparent;

UltraWebGrid1.Columns.FromKey("Edit").CellButtonStyle.BorderWidth = new Unit("0px");

UltraWebGrid1.Columns.FromKey("Edit").Width = new Unit("25px");

UltraWebGrid1.Columns.FromKey("Edit").Header.Caption = "Edt";

UltraWebGrid1.Columns.FromKey("Edit").CellStyle.CssClass = "GridBtnEdit";

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").EditorControlID = WebDateTimeEdit1.UniqueID;

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").Type = Infragistics.WebUI.UltraWebGrid.ColumnType.Custom;

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").EditorControlID = cmbReportDay.UniqueID;

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").Type = Infragistics.WebUI.UltraWebGrid.ColumnType.Custom;

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").DataType = "System.Int32";

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").IsBound = true;

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").EditorControlID = cmbReportSchFrequency.UniqueID;

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").Type = Infragistics.WebUI.UltraWebGrid.ColumnType.Custom;

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").DataType = "System.Int32";

this.UltraWebGrid1.Bands[0].Columns.FromKey("xxx").IsBound = true;

}

/// <summary>

/// bind dataset to the web combo.

/// </summary>

/// <param name="WC"> the web combo to bind</param>

/// <returns></returns>private void Fill_cmbs(WebCombo WC, DataTable dt)

{

try

{

WC.DataSource = dt;

WC.DataBind();

 

if (WC.Rows.Count > 0)

{

WC.Columns.FromKey(
"ID").Hidden = true;

}

}

catch (Exception ex)

{

ErrorMsg =
"Fill_cmbs Error: ";

Common.ZLog(System.Web.HttpContext.Current, ErrorMsg, ex);

HeaderImg m = (HeaderImg)Master;

m.DisplayErrorMsg(ErrorMsg + ex.Message);

}

}

protected void UltraWebGrid1_OnClickCellButton(object sender, CellEventArgs e)

{

if (rs == null) { rs = new ReportSchedules(); };

 

string sID = e.Cell.Row.Cells.FromKey("ID").ToString();

try

{

switch (e.Cell.Key.ToUpper())

{

case "EDIT":

break;

case "DELETE":

//rs.Delete(sID);

//UltraWebGrid1.Rows.Remove(e.Cell.Row);break;

}

}

catch (Exception ex)

{

ErrorMsg =
"UltraWebGrid1_OnClickCellButton Error: ";

Common.ZLog(System.Web.HttpContext.Current, ErrorMsg, ex);

HeaderImg m = (HeaderImg)Master;

m.DisplayErrorMsg(ErrorMsg + ex.Message);

}

}

Parents
No Data
Reply
  • 28464
    posted

    Issues like that are typically related to ASP.NET page life-cycle - e.g. at the time of adding the dynamic content it is already too late in order to add it to the control tree in such a way that it operates as expected. The WARP instance can also affect that.

    I have a couple of suggestions:

    1. Try using different events for adding the dynamic templated column to the Columns collection. Typically columns are added in the InitializeLayout event of the grid. You can also try Page.OnInit.

    2. Remove the WARP panel to see if this makes a difference.

Children
No Data