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
90
Message box in client-side BeforeSelectChangeHandler prevents postback
posted

I want to give the user the opportunity to cancel a row selection event by presenting them with a message box duing the BeforeSelectChangeHandler routine (which is the first chance you get to handle the scenario).

I'm finding that if I present a message box to ask them, this is enough to prevent a postback happening regardless if they let the event continue on.  If I take out the message box line the event does fire a postback.

Anyone any experience of this?  I'm using 2007 Vol 2.  Have a local sql server 2000 database running and the pubs database on it to start up the code.

Sample ASPX code:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Infragistics2.WebUI.UltraWebGrid.v7.2, Version=7.2.20072.61, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
    Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" %>

<!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>
    <script id="igClientScript" type="text/javascript">
<!--

function UltraWebGrid1_BeforeSelectChangeHandler(gridName, id)
{
    var checkbox;
    checkbox = document.getElementById('chkSelectionReturnValue');
    m_recordDiagostics('UltraWebGrid1_BeforeSelectChangeHandler returning ' + checkbox.checked + ' for row id ' + id);
   
    //confirm('Enter something.');
   
    return checkbox.checked;
}

function UltraWebGrid1_AfterSelectChangeHandler(gridName, id)
{
    var checkbox;
    checkbox = document.getElementById('chkSelectionReturnValue');
    m_recordDiagostics('UltraWebGrid1_AfterSelectChangeHandler returning ' + checkbox.checked + ' for row id ' + id);
    return checkbox.checked;
}

function UltraWebGrid1_BeforeRowActivateHandler(gridName, rowId)
{
    var checkbox;
    checkbox = document.getElementById('chkActivationReturnValue');
    m_recordDiagostics('UltraWebGrid1_BeforeRowActivateHandler returning ' + checkbox.checked + ' for row id ' + rowId);
    return checkbox.checked;
}

function UltraWebGrid1_AfterRowActivateHandler(gridName, rowId)
{
    var checkbox;
    checkbox = document.getElementById('chkActivationReturnValue');
    m_recordDiagostics('UltraWebGrid1_AfterRowActivateHandler returning ' + checkbox.checked + ' for row id ' + rowId);
    return checkbox.checked;
}

// This routine appends the message to the end of the diagnostics control.
function m_recordDiagostics(strMessage)
{
    var txtEventDiagnostics = document.getElementById("txtEventDiagnostics");
    var strCurrentValue;

    strCurrentValue = txtEventDiagnostics.value;
    strCurrentValue += strMessage + '\n';
    txtEventDiagnostics.value = strCurrentValue;   
}
// -->
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div width=100% height=100%>
        <div id="divDiags" style="WIDTH: 40%; HEIGHT: 100%; float:right">
            <asp:TextBox ID="txtEventDiagnostics" runat="server" Width="100%" Height="400px" TextMode="MultiLine"></asp:TextBox>
        </div>
        <asp:CheckBox ID="chkSelectionReturnValue" runat="server" Text="Return true from selection events when checked" />
        <asp:CheckBox ID="chkActivationReturnValue" runat="server" Text="Return true from activation events when checked" />
        <div style="WIDTH: 49%; HEIGHT: 100%">
        <igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" DataSourceID="SqlDataSource1" Width="50%" OnActiveRowChange="UltraWebGrid1_ActiveRowChange" OnDataBound="UltraWebGrid1_DataBound" OnInitializeLayout="UltraWebGrid1_InitializeLayout">
            <Bands>
                <igtbl:UltraGridBand>
                    <Columns>
                        <igtbl:UltraGridColumn BaseColumnName="au_id" IsBound="True" Key="au_id">
                            <Header Caption="au_id">
                            </Header>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="au_lname" IsBound="True" Key="au_lname">
                            <Header Caption="au_lname">
                                <RowLayoutColumnInfo OriginX="1" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="1" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="au_fname" IsBound="True" Key="au_fname">
                            <Header Caption="au_fname">
                                <RowLayoutColumnInfo OriginX="2" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="2" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="phone" IsBound="True" Key="phone">
                            <Header Caption="phone">
                                <RowLayoutColumnInfo OriginX="3" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="3" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="address" IsBound="True" Key="address">
                            <Header Caption="address">
                                <RowLayoutColumnInfo OriginX="4" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="4" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="city" IsBound="True" Key="city">
                            <Header Caption="city">
                                <RowLayoutColumnInfo OriginX="5" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="5" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="state" IsBound="True" Key="state">
                            <Header Caption="state">
                                <RowLayoutColumnInfo OriginX="6" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="6" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="zip" IsBound="True" Key="zip">
                            <Header Caption="zip">
                                <RowLayoutColumnInfo OriginX="7" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="7" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                        <igtbl:UltraGridColumn BaseColumnName="contract" DataType="System.Boolean" IsBound="True"
                            Key="contract" Type="CheckBox">
                            <Header Caption="contract">
                                <RowLayoutColumnInfo OriginX="8" />
                            </Header>
                            <Footer>
                                <RowLayoutColumnInfo OriginX="8" />
                            </Footer>
                        </igtbl:UltraGridColumn>
                    </Columns>
                    <AddNewRow View="NotSet" Visible="NotSet">
                    </AddNewRow>
                </igtbl:UltraGridBand>
            </Bands>
            <DisplayLayout AllowUpdateDefault="Yes" Name="UltraWebGrid1" RowHeightDefault="20px"
                SelectTypeRowDefault="Single" StationaryMarginsOutlookGroupBy="True" TableLayout="Fixed"
                Version="4.00" CellClickActionDefault="RowSelect" LoadOnDemand="Automatic">
                <FrameStyle BorderStyle="Double" BorderWidth="3px" Cursor="Default" Font-Names="Verdana"
                    Font-Size="8pt" Width="50%">
                </FrameStyle>
                <ClientSideEvents BeforeSelectChangeHandler="UltraWebGrid1_BeforeSelectChangeHandler" BeforeRowActivateHandler="UltraWebGrid1_BeforeRowActivateHandler" AfterSelectChangeHandler="UltraWebGrid1_AfterSelectChangeHandler" AfterRowActivateHandler="UltraWebGrid1_AfterRowActivateHandler" />
                <FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
                    <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
                </FooterStyleDefault>
                <HeaderStyleDefault BackColor="#065AC7" BorderStyle="Solid" ForeColor="White">
                    <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
                </HeaderStyleDefault>
                <RowStyleDefault BackColor="White" BorderColor="Gray" BorderStyle="None" BorderWidth="1px"
                    Font-Names="Verdana" Font-Size="8pt">
                    <Padding Left="3px" />
                    <BorderDetails ColorLeft="White" ColorTop="White" />
                </RowStyleDefault>
                <SelectedRowStyleDefault BackColor="#5796DE" ForeColor="White">
                </SelectedRowStyleDefault>
                <AddNewBox>
                    <BoxStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
                        <BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
                    </BoxStyle>
                </AddNewBox>
                <ActivationObject BorderColor="Black" BorderWidth="">
                </ActivationObject>
                <FilterOptionsDefault>
                    <FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
                        CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="11px" Width="200px">
                        <Padding Left="2px" />
                    </FilterDropDownStyle>
                    <FilterHighlightRowStyle BackColor="#151C55" ForeColor="White">
                    </FilterHighlightRowStyle>
                    <FilterOperandDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid"
                        BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif"
                        Font-Size="11px">
                        <Padding Left="2px" />
                    </FilterOperandDropDownStyle>
                </FilterOptionsDefault>
            </DisplayLayout>
        </igtbl:UltraWebGrid><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString %>"
            SelectCommand="SELECT * FROM [authors]"></asp:SqlDataSource>
            <asp:TextBox ID="TextBox1" runat="server" Height="186px" TextMode="MultiLine" Width="360px"></asp:TextBox></div>               
    </div>
    </form>
</body>
</html>
 

Same ASPX.CS code:

using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
   
    protected void UltraWebGrid1_ActiveRowChange(object sender, Infragistics.WebUI.UltraWebGrid.RowEventArgs e)
    {
        TextBox1.Text += "Row with id " + e.Row.DataSourceIndex + " fired event " + "ActiveRowChange" + System.Environment.NewLine;
    }
    protected void UltraWebGrid1_InitializeLayout(object sender, Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e)
    {
    }
    protected void UltraWebGrid1_DataBound(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            UltraWebGrid1.Rows[0].Selected = true;
            UltraWebGrid1.DisplayLayout.ActiveRow = UltraWebGrid1.Rows[0];
        }
    }
}
 

  • 90
    posted

    One thing I can do when the message box is displayed is to call igtbl_doPostBack('UltraWebGrid1') in the AfterSelectChangeHandler routine.

    This causes the postback to be fired properly. 

    Should happen automatically though.