AJAX n00b - custom server control in an UpdatePanel causes full postback


M

Monty

[apologies if this is the wrong newsgroup, couldn't find one for atlas/ajax]

Hi all,

I have a custom server control (inherits from control) that is, essentially,
a DIV containing a table with several rows, each of which has a DIV in it.
It is basically a menu of items. When the user clicks on an item div, the
event bubbles up to the table, the table calls __doPostBack and on the
server side the item is added to another DIV (let's call it
divSelectedItems). Works like a charm, but now I'd like to use an ASP.Net
AJAX UpdatePanel to do the updating of divSelectedItems when items are
selected. I put both my server control (the menu) and my divSelectedItems in
an updatepanel, but clicking on the items still causes a full postback. For
kicks, I put a button control in the update panel and add some text to the
divSelectedItems when the button is clicked. The button works with the
UpdatePanel (ie, does not cause a full postback) but my server control does
not. How can I get the UpdatePanel to convince my server control to use it's
AJAX magic rather than doing a full postback?? TIA!

-Monty
 
Ad

Advertisements

M

Monty

Brief update:

I tried explicitly adding my control as a trigger (I thought this was
unecessary for controls that were IN the updatepanel, but apparently not?).
It added it like so:

Dim o As New Web.UI.AsyncPostBackTrigger()
o.ControlID = lobItems.UniqueID
o.EventName = "Click"
UpdatePanel1.Triggers.Add(o)



Now it works for the FIRST CLICK only, after that it's back to a full
postback again. Any help? Thanks...
 
W

Walter Wang [MSFT]

Hi Monty,

Without complete code of your menu-like control, it's hard to say which
part went wrong. However, we do have some guidelines on how to write an
ASP.NET AJAX-aware control:

#ASP.NET Forums - HOWTO: Write controls compatible with UpdatePanel without
linking to the ASP.NET AJAX DLL
http://forums.asp.net/thread/1445844.aspx

Please refer to above document and modify your control accordingly, and
feel free to let me know if you have any questions.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Monty

That is a cool article, and I implemented it in my server control, but it
did not affect the main issue I am experiencing:

The first click on my "trigger" control does an async postback perfectly -
great! The second click on it causes a full postback. Repeat ad nauseum. Any
ideas? Thanks.
 
W

Walter Wang [MSFT]

Hi Monty,

If done correctly, the control should have no idea of AJAX but still could
update without full page postback if placed inside a UpdatePanel. Would you
please post some code or send me a reproducible web project so that I can
help find the root cause? Thanks.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ad

Advertisements

B

baradi hakim

Hi,

I have the same problem, didi anyone resolve it ?

this is my code :

public class RightTable : Control, INamingContainer
{
...
protected override void CreateChildControls()
{
this.iNbColomns = this.ColomnHeaders.Length;
this.iNbRows = this.RowHeaders.Length;

if (this.iNbColomns > 0 && this.iNbRows > 0)
{
//tblConteneur
tblConteneur = new Table();
//tblConteneur.BorderWidth = Unit.Pixel(1);
TableCell td1;
TableRow tr1 = new TableRow();
//initialisation
for (int i = 0; i < this.iNbColomns + 1; i++)
{
td1 = new TableCell();
tr1.Cells.Add(td1);
}
tblConteneur.Rows.Add(tr1);

TableRow tr2 = new TableRow();
tr2.CssClass = this.HeaderStyle;

TableCell td2 = new TableCell();
td2.Text = (this.HeaderStyle != null && this.HeaderStyle
!= "" ? "<font class=\"" + this.HeaderStyle + "\">" : "") + this.Heading
+ (this.HeaderStyle != null && this.HeaderStyle != "" ? "</font>" : "")
;
tr2.Cells.Add(td2);

//first line with colomn headers
for (int i = 0; i < this.iNbColomns; i++)
{
td2 = new TableCell();
td2.BorderWidth = Unit.Pixel(1);
LinkButton lbColumnHeader = new LinkButton();
Header oColomnHeder = this.ColomnHeaders;
lbColumnHeader.Text = (this.HeaderStyle != null &&
this.HeaderStyle != "" ? "<font class=\"" + this.HeaderStyle + "\">" :
"") + oColomnHeder.Name + (this.HeaderStyle != null && this.HeaderStyle
!= "" ? "</font>" : "");
lbColumnHeader.CommandArgument =
oColomnHeder.Id.ToString();
lbColumnHeader.Click += new
EventHandler(LBColumnHeader_Click);
td2.Controls.Add(lbColumnHeader);
tr2.Cells.Add(td2);
}
tblConteneur.Rows.Add(tr2);

bool bStyleAlernate = true;
for (int j = 0; j < this.iNbRows; j++)
{
TableRow trx = new TableRow();
if (bStyleAlernate)
trx.CssClass = this.RowStyle;
else
trx.CssClass = this.AlternatingRowStyle;

bStyleAlernate = !bStyleAlernate;

TableCell tdx = new TableCell();
tdx.BorderWidth = Unit.Pixel(1);
tdx.CssClass = this.HeaderStyle;
LinkButton lbRowHeader = new LinkButton();
RowHeader oRowHeader = this.RowHeaders[j];
lbRowHeader.Text = (this.HeaderStyle != null &&
this.HeaderStyle != "" ? "<font class=\"" + this.HeaderStyle + "\">" :
"") + oRowHeader.Name + (this.HeaderStyle != null && this.HeaderStyle !=
"" ? "</font>" : "");
lbRowHeader.CommandArgument =
oRowHeader.Id.ToString() + "," + ((int)oRowHeader.RowType).ToString();
lbRowHeader.Click += new
EventHandler(LBRowHeader_Click);
tdx.Controls.Add(lbRowHeader);
trx.Cells.Add(tdx);

for (int i = 0; i < this.iNbColomns; i++)
{
tdx = new TableCell();
tdx.BorderWidth = Unit.Pixel(1);
if (this.Values[j] != null)
{
TableCase TC = this.Values[j];
RightCheckBox T2dCb = new
RightCheckBox(TC.RowId, TC.ColomnId, oRowHeader.RowType);
T2dCb.Checked = TC.Value;
T2dCb.AutoPostBack = true;
T2dCb.CheckedChanged += new
EventHandler(CheckBoxRight_CheckedChanged);
tdx.Controls.Add(T2dCb);
}
trx.Cells.Add(tdx);
}
tblConteneur.Rows.Add(trx);
}

this.Controls.Add(tblConteneur);
}

this.OnControlCreated();

this.EnabledDisabledControl(this.Controls, "", true);
}
}

===>
In my case the CheckBox enable UpdatePanel, but not the LinkButon
Controls
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top