Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Using ajax in ASCX control View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 9/24/2012 8:07:25 PM
   
Using ajax in ASCX control
HI Guys,

We are running Kentico 6 on asp.net 4.0.
I have added a webpart "User Control".

This webpart control looks at my ascx file.

My ascx code has got a button with an onclick="Button_Click" event.
So when the button is clicked it looks at the event in the code behind and triggers the event. Everything works fine. But is there a way to trigger the event without refreshing the whole page. So I wanty only a certain labels to get updated and not the whole page. I am sure it can be done with ajax but I am not sure how kentico works.

Any help is appreciated. If you can refer to a link with an example would be even great.

Thanks
Gitesh Shah

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 9/26/2012 9:04:30 AM
   
RE:Using ajax in ASCX control
Hi Gitesh,

You should be able to achieve the behavior by wrapping your control into the UpdatePanel.
This can be done by enabling Use update panel: setting in the User control web part properties.
Please see AJAX support in web parts article, e.g. the note that if the web part uses dynamically loaded controls, you will have to define their IDs...

Should you need any additional details, please feel free to ask.

Regards,
Zdenek.

User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 10/2/2012 10:13:24 PM
   
RE:Using ajax in ASCX control
Hi Zdenek,

Thanks for the link to the article.

I am having a ascx file with the below code. "User Control" webpart has got ajax ticked.
My ASCX page

<asp:Button id="TestButton" runat="server" OnClick="Button_Clicked" Text="Test button" />

My ASCX.cs page

protected void click(object sender, EventArgs e)
{
TestButton.Text = "test success";
}


It is displaying the button fine and works but when clicked it refreshes the whole page but we just want to refresh that label not the whole page.

Where do I need to keep the below line:
CMS.ExtendedControls.ControlsHelper.GetPostBackEventReference(this, "");

Thanks
Gitesh Shah

User avatar
Certified Developer v7
Certified  Developer v7
Gitesh - 10/9/2012 6:10:06 PM
   
RE:Using ajax in ASCX control
Any one?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 10/12/2012 8:22:20 AM
   
RE:Using ajax in ASCX control
Hi,

The difference between the set OnClick action name and the "click" method name in the code behind is probably causing no action to be performed, however, the whole page refresh is caused by something different probably.
Which version are you using for this project BTW?

I would recommend to read following tutorial article on UpdatePanel triggers and try to use them:
http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers. It contains the examples too.

As for the GetPostBackEventReference - I believe it's not needed for your aim. It is usually used in OnLoad phase, before registering a client script block... some examples can be see in our controls (try to search in .cs files for the method call to find some examples).

Is this helpful?

Regards,
Zdenek