Showing posts with label home. Show all posts
Showing posts with label home. Show all posts

Saturday, March 24, 2012

Load ascx in other Page using Ajax

I have one application, which has one Home.aspx, Head.Ascx and Footer.Ascx, Head.aspx has two button, And all controls of head.ascx and footer.ascx in ajax panel, now in home page when i click on one button then i want to load head.ascx in my Home page and if i click on second button then i want to load footer.aspx in Home page and unload Head.ascx. I am using ajax in my application. But not enable to solve this.

Thanks

Hi,

Here is an example made according to your requirement:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void btnHeader_Click(object sender, EventArgs e) { ViewState["show"] = "h"; } protected void btnFooter_Click(object sender, EventArgs e) { ViewState["show"] = "f"; } protected void Page_PreRender(object sender, EventArgs e) { if (ViewState["show"] != null) { string show = ViewState["show"].ToString(); if (show == "h") { Control ctrl = this.LoadControl("Header.ascx"); PlaceHolder1.Controls.Add(ctrl); } else { Control ctrl = this.LoadControl("Footer.ascx"); PlaceHolder1.Controls.Add(ctrl); } } }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="btnHeader" runat="server" Text="Show Header" onclick="btnHeader_Click" /> <asp:Button ID="btnFooter" runat="server" Text="Show Footer" onclick="btnFooter_Click" /> <asp:Button ID="Button3" runat="server" Text="Another Button" /> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Thanks Raymond Wen , it solved

Load different content pages in content place holder without refreshing the whole page usi

Hi,

I have built a ajax enabled website, where i have a master page which holds a content placeholder, and two content pages, where one is the home screen and another is a dashboard, a menu is placed in master page , by default home page is made to display, when the menu item dashboard is clicked , the the contentplace holder should load the dashboard page without postbacking the whole page, how to do that through ajax? Pleas help me.....

Its very urgent, I am stucked.....

hello.

i'd say that you cannot do that in your scenario. i'd refactor the site and transform the contents of the main page and the other page in user controls. then, i'd build only one page set its content to one of the user controls...


Luis Abreu:

hello.

i'd say that you cannot do that in your scenario. i'd refactor the site and transform the contents of the main page and the other page in user controls. then, i'd build only one page set its content to one of the user controls...

Hi Luis,

I am new in creating webapplication. I am not able to get what u'r saying.

Plese explin me in details, What is usercontrol ? How does it satisfy my needs?

Please help me. Give me an example, whre they have used user control .....

Thanks in advance


here's an old post that shows how you might change the user controls on an udpate panel:

http://msmvps.com/blogs/luisabreu/archive/2007/02/15/adding-controls-to-an-updatepanel-through-code.aspx

regarding the user control part, well, it's really the easiest way you have to develop a control. i think that if you go to the asp.net site, you'll be able to get lot of info from the quick starts