Hi All,
I am implementing a custom gridview control, that emits some javascript to blink a row whenever a new row is added in gridview. The gridview is inside the <asp:updatepanel> for parital page rendering. The problem is when I put the gridview inside the updatepanel, I don't see the HTML table that is created as a result from rendering the gridviewcontrol and thus when new row is added, it does not blink, however when i just put the gridview without update panel, it the row blinks. How can I do that ?
custom gridview control code:
public class AlertWebControl : GridView
{
[Browsable(true)]
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
private string rowid;
protected override void RenderContents(HtmlTextWriter output)
{
base.RenderContents(output);
}
protected override void OnRowDataBound(GridViewRowEventArgs e)
{
base.OnRowDataBound(e);
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowIndex == this.Rows.Count)
{
rowid = e.Row.ClientID;
}
}
protected override void OnDataBound(EventArgs e)
{
base.OnDataBound(e);
if (this.Rows.Count > 1)
{
}
}
public override void UpdateRow(int rowIndex, bool causesValidation)
{
base.UpdateRow(rowIndex, causesValidation);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
string jscode = null;
string jskey = "jskey";
jscode = @"<script language='javascript' type='text/javascript'>
var counter=1000;
var cellId=null;
var m_TheCurrentRow = null;
function BlinkRow( theRowObj )
{
m_TheCurrentRow = theRowObj;
window.setTimeout(ShowBaseColor, 1000);
}
function ShowBaseColor()
{
document.getElementById(m_TheCurrentRow.id).style. backgroundColor='#C1DAD7';
document.getElementById(m_TheCurrentRow.id).style. color='black';
counter += 1000;
if(counter <= 10000)
{
window.setTimeout(ShowChangeColor, 1000);
}
}
function ShowChangeColor()
{
document.getElementById(m_TheCurrentRow.id).style. backgroundColor='white';
document.getElementById(m_TheCurrentRow.id).style. color='black';
counter += 1000;
window.setTimeout(ShowBaseColor, 1000)
}
</script>";
if (!Page.ClientScript.IsStartupScriptRegistered(jske y))
{
Page.ClientScript.RegisterStartupScript(this.GetTy pe(), jskey, jscode);
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (this.Rows.Count > 0)
{
string rowkey = "rowkey";
string script = "<script language='javascript'>";
script += "BlinkRow(document.getElementById(\"" + rowid + "\"))";
script += "</script>";
Page.ClientScript.RegisterStartupScript(this.GetTy pe(), rowkey, script);
rowkey = null;
script = null;
}
}
}
Aspx page from where I am accessing the control inside updatepanel
<form runat="server" action="#">
<asp:ScriptManager ID="scrMgr" runat="server" EnablePartialRendering="true"/>
<asp:Timer ID="alerttmr" OnTick="GetAlerts" runat="server" Interval="10000">
</asp:Timer>
<asp:UpdatePanel ID="alertpanel" runat="server" UpdateMode="Conditional" RenderMode="Block">
<Triggers >
<asp:AsyncPostBackTrigger ControlID="alerttmr" />
</Triggers>
<ContentTemplate>
<cc1:AlertWebControl ID="AlertWebControl1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Order Id" DataField="OrderId" />
<asp:BoundField HeaderText="Line" DataField="Line" />
<asp:BoundField HeaderText="BuySell" DataField="BuySell" />
<asp:BoundField HeaderText="Quantity" DataField="Quantity" />
<asp:BoundField HeaderText="Symbol" DataField="Symbol" />
</Columns>
</cc1:AlertWebControl>
</ContentTemplate>
</asp:UpdatePanel>
</form>