467,879 Members | 1,210 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

Custom gridview with ajax updatepanel

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>
Aug 21 '07 #1
  • viewed: 2799
Share:
1 Reply
nateraaaa
Expert 512MB
The GridView cannot be used in an updated panel. A gridview requires a full post back and will not function properly using a partial page postback. Please see this site for additional details.

Nathan
Aug 21 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by davidjgonzalez | last post: by
reply views Thread by Reinhard | last post: by
1 post views Thread by =?Utf-8?B?cmxt?= | last post: by
13 posts views Thread by SAL | last post: by
8 posts views Thread by Nick | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.