using AJAX with dynamically created web controls in C#.NET

N

nat

Hi all,

I was going to post this in the AJAX forum, but apparently someone
posted an AJAX/C# question in there today and was told to try this
forum instead. So here goes:

I'm trying to figure out whether AJAX will work with dynamically
created controls in C#.NET. I have been able to get non-dynamically
created controls to work, but so far none of my dynamic controls or
events linked to them are able to work with AJAX. Does anyone know how
or if I can do this? The dynamically created controls are created on a
placeholder control. I can get the code to work perfectly without AJAX,
but now we want there to not be any postbacks whenever the user clicks
on a linkbutton or a button.

Tks
 
M

Michael Nemtsev

Hello nat,

What do you use for AJAX? your own implementation or 3rd part one?
In general, AJAX libs have a placeholder, within your component works asynchronously.

It doesn't depend whether you put it statically or dinamically


n> I was going to post this in the AJAX forum, but apparently someone
n> posted an AJAX/C# question in there today and was told to try this
n> forum instead. So here goes:
n>
n> I'm trying to figure out whether AJAX will work with dynamically
n> created controls in C#.NET. I have been able to get non-dynamically
n> created controls to work, but so far none of my dynamic controls or
n> events linked to them are able to work with AJAX. Does anyone know
n> how or if I can do this? The dynamically created controls are created
n> on a placeholder control. I can get the code to work perfectly
n> without AJAX, but now we want there to not be any postbacks whenever
n> the user clicks on a linkbutton or a button.
n>
n> Tks
n>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
N

nat

I have tried using MagicAjax, as well as the simple Ajax.dll. I tried
to use ASP.NET Atlas, but it wouldn't work with our version of VS.NET
(we're using 1.1 and 2003). I even downloaded a control that was
supposed to be able to make this simpler, the Callback control from
AspxLab, but this particular control doesn't work with the free
download, and we can't afford a license just to see if this 'might'
work. Any ideas on what I could use? And a sample? For instance, some
of my C# code is:

public void SaveItemName(){
Label lblItemName = new Label();
TextBox txtItemName = new TextBox();
Button btnSaveItem = new Button();
lblItemName.Text = "Item Name: ";
txtItemName.ID = "txtItemName";
btnSaveItem.Text = "Save Item";
btnSaveItem.Click += new EventHandler(btnSaveItem_Click);
PlaceHolder1.Controls.Add(lblItemName);
PlaceHolder1.Controls.Add(txtItemName);
PlaceHolder1.Controls.Add(btnSaveItem);
}
 
A

aspxlab

Hi nat,

Our Callback control is fully functional without a license. The only
difference between the licensed and unlicensed version is that
unlicensed version randomly displays a license warning message.

So you should be able to try it out to see if it works for you without
purchasing a license. Please contact our support staff if you need any
help on how to use it (After all, we wouldn't put it out there for
download if there is no chance for you to run it to see if it works
:p).

The sample package contains full source code of the demo project, an
online version of which can be found at:
http://www.aspxlab.com/AspxLabDemo/Callback/CallbackDemo.aspx

You can also find detailed documentation at:
http://www.aspxlab.com/doc/index.html

Thanks
AspxLab Support
http://www.aspxlab.com
 
M

Michael Nemtsev

Hello nat,

Afaik, there were no problem with MajicAjax. I've used it, but need to look
at code how it worked with dynamic contols

n> I have tried using MagicAjax, as well as the simple Ajax.dll. I tried
n> to use ASP.NET Atlas, but it wouldn't work with our version of VS.NET
n> (we're using 1.1 and 2003). I even downloaded a control that was
n> supposed to be able to make this simpler, the Callback control from
n> AspxLab, but this particular control doesn't work with the free
n> download, and we can't afford a license just to see if this 'might'
n> work. Any ideas on what I could use? And a sample? For instance, some
n> of my C# code is:
n>
n> public void SaveItemName(){
n> Label lblItemName = new Label();
n> TextBox txtItemName = new TextBox();
n> Button btnSaveItem = new Button();
n> lblItemName.Text = "Item Name: ";
n> txtItemName.ID = "txtItemName";
n> btnSaveItem.Text = "Save Item";
n> btnSaveItem.Click += new EventHandler(btnSaveItem_Click);
n> PlaceHolder1.Controls.Add(lblItemName);
n> PlaceHolder1.Controls.Add(txtItemName);
n> PlaceHolder1.Controls.Add(btnSaveItem);
n> }
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
N

nat

OK, well I followed the sample code on the aspxlab site, but it still
didn't work. (and yes, I saw the message that said I needed a license
-- but I have to say that when I checked your site, I noticed that
there was a paragraph that effectively said that the callback control
did not have a free version, even though you could download it). I'll
look into the documentation some more, to verify whether I just wasn't
putting in all the correct code.
 
N

nat

Hi Michael,

I would appreciate if you could see whether MajicAjax worked with
dynamic controls. This has just become such a PITA for me lately, and
no-one at my office knows much about Ajax.

tks
 
A

aspxlab

Hi Nat,

You can download all our controls for evaluation purpose, but it's a
comercial control, so it's not free. We do have a free basic edition
Menu and Slide Menu, but unfortunately not the Callback control at this
time.

As for reasons that it didn't work for you, it may has to do with your
code. I would suggest you to start with these walkthroughs:
http://www.aspxlab.com/doc/callback_walkthru_productInfo.html
http://www.aspxlab.com/doc/callback_walkthru_send_request.html
http://www.aspxlab.com/doc/callback_walkthru_retrieve_data.html

Note that unlike many other products, we do not need a "PlaceHolder"
object (This might be where you confused). Our Callback controls is a
container control and you can put other controls in it, the Callback
boundary defines the part of the page that needs to be dynamically
updated. (You can also use the Callback in a data transfer mode).

I would recommend you take a look of the sample package source code (by
selecting "Live Demo Source Code" when you install the control, you
need IIS to check this option). Also feel free to contact our support
if you need to. We do provide free support to all evaluation users.

Thanks
AspxLab Support
http://www.aspxlab.com
 
M

Michael Nemtsev

Hello nat,

Could u show the code, how you add control dynamically?

n> Hi Michael,
n>
n> I would appreciate if you could see whether MajicAjax worked with
n> dynamic controls. This has just become such a PITA for me lately, and
n> no-one at my office knows much about Ajax.
n>
n> tks
n>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
M

Michael Nemtsev

Hello nat,

I've tested it now, and everything works ok.

see code below

protected System.Web.UI.WebControls.Button Button1;
protected MagicAjax.UI.Controls.AjaxPanel AjaxPanel1;
protected TextBox textBox1;
private void Page_Load(object sender, System.EventArgs e)
{
textBox1 = new TextBox();
AjaxPanel1.Controls.Add(textBox1);

}

private void Button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = "Test";

}

textBox is created dynamically whithin AjaxPanel1. Now we open Fiddler, load
page, press Button1 and see logs of Fidler.
And we gets as response

AJAXCbo.ExtendedSetHtmlOfElement("<input name=\"_ctl0\" type=\"text\" value=\"Test\"
/>","_ctl0$ajaxdest");
AJAXCbo.SetField("__CONTROL_FINGERPRINTS_AjaxPanel1","53FADAD5;_ctl0#EC8B2D08;Button1#C96272A5");
'AJAX_LOADING_OK';

textBox.Text property was set with asynch call



n> Hi Michael,
n>
n> I would appreciate if you could see whether MajicAjax worked with
n> dynamic controls. This has just become such a PITA for me lately, and
n> no-one at my office knows much about Ajax.
n>
n> tks
n>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
S

Satheesh Kumar

Hi,

There is a tool called "component art"... In that CallBack functionality
is ther,which implements AJAX for dynamically created 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