Showing posts with label usercontrol. Show all posts
Showing posts with label usercontrol. Show all posts

Wednesday, March 28, 2012

Linkbutton not working, Imagebutton OK

I placed a usercontrol inside an updatepanel.

The usercontrol has a placeholder, and to that placeholder I add imagebuttons and linkbuttons.

When the imagebuttons are clicked, a partial update of the page is done = GOODSmile

When an linkbutton is clicked, a full update of the page is done = BADAngry (No javascript errors whatsoever).

Does asp.net ajax treat this two types of controls differently? Did I forget to do extra steps?

Regards,

Fizgig



Does anyone have a solution for this? I'm getting the same results with a <asp:LinkButton>. When I try with <asp:Button>, it works perfectly.

This works for me.

<formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/><asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"><ContentTemplate><asp:PlaceHolderID="PlaceHolder1"runat="server"><asp:ImageButtonID="ImageButton1"ImageUrl="Untitled-1.gif"runat="server"/><br/><br/><asp:LinkButtonID="LinkButton1"runat="server">LinkButton</asp:LinkButton><br/><br/></asp:PlaceHolder><asp:LabelID="lblTest"runat="server"Text="Label"></asp:Label></ContentTemplate></asp:UpdatePanel><div><asp:LabelID="lblTest2"runat="server"Text="Label"></asp:Label></div></form>

Hi Fizgig,

I tried dynamic imageButton, it works fine.

See this:

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partialclass Ajax_Default2 : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) { LinkButton lb =new LinkButton();this.PlaceHolder1.Controls.Add(lb); lb.Text ="Linkbutton"; lb.ID ="lb1"; lb.Click +=new EventHandler(lb_Click); ImageButton ib =new ImageButton();this.PlaceHolder1.Controls.Add(ib); ib.ID ="ib1"; ib.ImageUrl ="~/images/add.gif"; ib.Click +=new ImageClickEventHandler(ib_Click); Label2.Text = DateTime.Now.ToString(); }void ib_Click(object sender, ImageClickEventArgs e) { Label1.Text ="ib1 clicked on " + DateTime.Now.ToString(); }void lb_Click(object sender, EventArgs e) { Label1.Text ="lb1 clicked on " + DateTime.Now.ToString(); }}

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

Maybe it's fixed in the current Ajax version. Thanx.

I am receiving the same error that was reported in the original post. In my case I have a link button and an image button and so I'm able to hack this together by setting the OnClientClick property of the LinkButton to <%# "document.getElementById('" + Thumbnail.ClientID + "').click();return false;" %> - which is not very elegant, but works fine. Hopefully later I'll have a chance to better isolate this issue - I've run into it a couple times, but am not sure what the variable is yet.


I found that you have to add a trigger for the link button, so here's what you have to add, where lb is my linkbutton, and upPanel is the update panel that contains the link button...

AsyncPostBackTrigger asbt = new AsyncPostBackTrigger();
asbt.ControlID = lb.ID;
asbt.EventName = "Click";
upPanel.Triggers.Add(asbt);


Good find. That makes sense - although it's peculiar that it works different for the LinkButton and ImageButton. Thanks for posting that.

Saturday, March 24, 2012

Load On-demand using PopupControlExtender

Hi-

I am displaying a Panel that contains a web usercontrol using PopupControlExtender in AJAXToolKit. Since the web usercontrol has pretty expensive database task, I would like to display the Panel only when a user clicked on a link that displays the PopupControlExtender.

Is there a way to accomplish this? Please advice.

Regards,

Prabhu

Hi Prabhu,

According to my understanding to your question, you plan to load contents of a popup dynamically via asynchronous request.

Here isa thread that implement dynamical loading with TabContainer extender, you may try the same solution. The only difference is that you may need to invoke the method that fetches data in popup showing event handler. For instance:

<ajaxToolkit:PopupControlExtender ID="PopupControlExtender2" runat="server"BehaviorID="pce" ......... />
function pageLoad(sender, args)
{
$find("pce")._popupBehavior.add_showing(onPopupShow);

}

function onPopupShow(sender, args)
{
// get data dynamically here
}

Hope this helps.

Wednesday, March 21, 2012

Load UserControl After PageLoad is completed

I'm still pretty new to the ajax / javascript scene, so I'm finding myself stumped on what may be a very simple thing. If anybody can point me in the right direction, I will be very grateful.

What I have is this:

I have a user control that has an update panel wrapped around a listview control that gets data from a data source.

I have a page that has the user control on it.

What I want to happen is for the page to load then the user control to go get its data and refresh the listview. Something like pageflakes. Where the page loads while the widgets are updating themselves, except in this case it will be a user control updating.

Is this possible? If so, can somebody point me in the right direction?

Thanks in advance!!

Kendra

http://mattberseth.com/blog/2007/07/delay_load_an_updatepanel.html

http://mattberseth.com/blog/2007/06/aspnet_ajax_canceling_an_async_1.html


Thank you thank you thank you... i have read tons of Matt's articles and hadn't run across this one yet. Of course, using the right search term helps as well.

Loading an Atlas enabled UserControl Dynamically. Urgent!

Hello,

I have 2 buttons within an UpdatePanel (for the menu) and another UpdatePanel (for the Content) where I load a control depending of the menu clicked.

MyControl1.ascx and MyControl2.ascx both content an UpdatePanel too.

Default.aspx:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>

<html>

<headid="Head1"runat="server">

<title></title>

<Atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"/>

</head>

<body>

<formid="form1"runat="server">

<div>

<Atlas:updatepanelid="UpdatePanel1"runat="server"mode="Conditional"rendermode="Inline">

<contenttemplate>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/>

<asp:ButtonID="Button2"runat="server"Text="Button"OnClick="Button2_Click"/>

</contenttemplate>

</Atlas:updatepanel>

<br/>

<Atlas:updatepanelid="UpdatePanel2"runat="server"mode="Conditional"rendermode="Inline">

<Triggers>

<Atlas:ControlEventTriggerControlID="Button1"EventName="Click"/>

<Atlas:ControlEventTriggerControlID="Button2"EventName="Click"/>

</Triggers>

<contenttemplate>

<asp:PlaceHolderID="PlaceHolder1"runat="server"></asp:PlaceHolder>

</contenttemplate>

</Atlas:updatepanel>

</div>

</form>

</body>

</html>

Default.aspx.cs:

using System;

using System.Text;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclass _Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedoverridevoid OnInit(EventArgs e)

{

base.OnInit(e);

if (Session["ContentControl"] !=null)

{

Control c = LoadControl(Session["ContentControl"].ToString());

PlaceHolder1.Controls.Add(c);

}

}

protectedvoid Button1_Click(object sender,EventArgs e)

{

Session["ContentControl"] ="/MyContent1.ascx";

}

protectedvoid Button2_Click(object sender,EventArgs e)

{

Session["ContentControl"] ="/MyContent2.ascx";

}

}

MyContent1.ascx:

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="MyContent1.ascx.cs"Inherits="MyContent1"%>

<IGI:updatepanelid="Updatepanel1"runat="server"mode="Conditional"rendermode="Inline">

<contenttemplate>

MyContent1

</contenttemplate>

</IGI:updatepanel>

MyContent2.ascx:

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="MyContent2.ascx.cs"Inherits="MyContent2"%>

<IGI:updatepanelid="Updatepanel1"runat="server"mode="Conditional"rendermode="Inline">

<contenttemplate>

MyContent2

</contenttemplate>

</IGI:updatepanel>

My problem is I have to click twice on a button for the Content control to load because the OnInit is executed before theButton1_Click.( the session is not updated yet when the OnInit is executed );

Anybody has an idea to achived this in One Click??

Many Thanks,

Yann

Did anyone every respond to you on this question? I am having the same problem, and I could only solve it (kind of) by using a master page.

I wrapped the ContentPlaceHolder in the master page inside an UpdatePanel, and in my actual page, I put another PlaceHolder for holding my dynamically created user control (or other type of control based on my portal's configuration).

I would like to know if anyone ever answers this, and I would also like to be able to use WebParts in this scenario, which I have NEVER gotten to work with Atlas and dynamic user controls reliably.

Loading UserControl Dynamically in UpdatePanel

i'm using this technique (http://geekswithblogs.net/rashid/archive/2007/08/11/Loading-UserControl-Dynamically-in-UpdatePanel.aspx). it works well.

however, i'm trying to add javascript to UserControl2 and the javascript never executes. it appears that the javascript never renders to the page.

help.

What approach are you using to add the JavaScript?

-Damien


i've tried embedding the javascript directly onto the page. i've also tried adding the javascript via using RegisterStartupScript in my Page_Load event.


Ensure you are using ScriptManager RegisterXXX method instead of Page.