Sunday, March 11, 2012

Partitial page update across aspx pages, that contain different content

Actually yes, you should use AJAX for the 2 contents. Use 2 UserControls on the page to do that. So default.ascx and Login.ascx and then add 2 updatepanels in each usercontrol and add them into the page.

Have fun


Thank you for your Reply!

I am relatively new to ASP.NET so i did not know about Usercontrols ;) I worked with these controls partly successfully. But i have to create them dynamically depending on the clicked Menu Buttons (otherwise i have to activate/deactivate visibility which would require too much Page Code if i have a large application and load every single control in that page), and this is where a new story with many problems begins ... I read a lot about errors using dynamic usercontrols and update panels that only can be solved if i use workarounds which decrease security or functionality, so i think i will not use an complete AJAX Page but only for specific elements until these problems are fixed.

greets, Jan


Hi Jan;

U could try to put this in your updatepanel in your masterpage: this would avoid to update for every request
UpdateMode="Conditional"ChildrenAsTriggers="false"

And then place other i.e. 2 updatepanels in your aspx file and use yourUpdatePanelID.Update() command whenever needed..

This should solve your problem if I didn't get you wrong..

Tschüzz:)


Ohh sorry I got you now:D and I realised I was totally wrong:) Well this sounds really good for UI but about performance I'm not sure..

When u wanna switch between pages you have to make a response and request for different urls from the server so it doesn't sound possible but I'm not sure. On the other hand what u can do, since ur programmatically adding your controls, is to unite your pages in one page in different content place holders or even in different panels; and then programmatically add and remove them by updating updatepanels individually...

Hope this helps..

Even not I would like to hear bout your solution:)


Hi Kaan ;)

My current state: My approach is to dynamically load a Usercontrol into a contentplaceholder depending on the Button that was clicked. Because the menu and the contentplaceholder are in seperate update panels, they are independently updated.

File aspx:TestUserControlWithMasterPage.aspx

2<%@. Page Language="VB" MasterPageFile="~/TestMasterPageDynUserCTR.master" AutoEventWireup="false" CodeFile="TestUserControlWithMasterPage.aspx.vb"Inherits="TestUserControlWithMasterPage" title="Untitled Page" %>
3<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
4</asp:Content>

File Master: TestUserControlWithMasterPage.aspx

1<%@. Master Language="VB" CodeFile="TestMasterPageDynUserCTR.master.vb"Inherits="TestMasterPageDynUserCTR" %>2<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">3<html xmlns="http://www.w3.org/1999/xhtml" >4<head runat="server">5 <title>Unbenannte Seite</title>6</head>7<body>8 <form id="form1" runat="server">9 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">10 </asp:ScriptManager>11 <div>12 <asp:UpdatePanel ID="UpdatePanelMenu" runat="server" UpdateMode="Always">13 <ContentTemplate>14 <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/testusercontrolwithmasterpage.aspx">Grid</asp:LinkButton>15 <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl="~/testusercontrolwithmasterpage.aspx">Login</asp:LinkButton><br />16 </ContentTemplate></asp:UpdatePanel>1718 <asp:UpdatePanel ID="UpdatePanelContent" runat="server" UpdateMode="Always" >19 <ContentTemplate>20 <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">21 </asp:contentplaceholder>22 </ContentTemplate></asp:UpdatePanel>23 </div>24 </form>25</body>26</html>27


File Master -Code Behind: TestUserControlWithMasterPage.aspx.vb

1PartialClass TestMasterPageDynUserCTR2Inherits System.Web.UI.MasterPage3Protected Sub LinkButton1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles LinkButton1.Click4If Page.FindControl("TestWebUserControl1.ascx")Is Nothing Then5 Dim GridAs Control = LoadControl("TestWebUserControl1.ascx")6 ContentPlaceHolder1.Controls.Clear()7 ContentPlaceHolder1.Controls.Add(Grid)8End If9 End Sub10 Protected Sub LinkButton2_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles LinkButton2.Click11Dim LoginAs Control = LoadControl("TestWebUserControl2.ascx")12 ContentPlaceHolder1.Controls.Clear()13 ContentPlaceHolder1.Controls.Add(Login)14End Sub15End Class

File ascx 1:

1<%@. Control Language="VB" AutoEventWireup="false" CodeFile="TestWebUserControl1.ascx.vb"Inherits="TestWebUserControl1" %>234hallo<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"5 DataSourceID="SqlDataSource1" DataKeyNames="ProjectID">6 <Columns>7 <asp:BoundField DataField="ProjectID" HeaderText="ProjectID" InsertVisible="False"8ReadOnly="True" SortExpression="ProjectID" />9 <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID" />10 <asp:BoundField DataField="CreateDate" HeaderText="CreateDate" SortExpression="CreateDate" />11 <asp:BoundField DataField="StartDate" HeaderText="StartDate" SortExpression="StartDate" />12 <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />13 <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />14 <asp:CheckBoxField DataField="Finished" HeaderText="Finished" SortExpression="Finished" />15 <asp:BoundField DataField="Budget" HeaderText="Budget" SortExpression="Budget" />16 <asp:BoundField DataField="EndDate" HeaderText="EndDate" SortExpression="EndDate" />17 <asp:BoundField DataField="LastModified" HeaderText="LastModified" SortExpression="LastModified" />18 <asp:BoundField DataField="GanttChartID" HeaderText="GanttChartID" SortExpression="GanttChartID" />19 <asp:BoundField DataField="ProjectComplexity" HeaderText="ProjectComplexity" SortExpression="ProjectComplexity" />20 <asp:BoundField DataField="VisionID" HeaderText="VisionID" SortExpression="VisionID" />21 <asp:BoundField DataField="StakeholdersID" HeaderText="StakeholdersID" SortExpression="StakeholdersID" />22 <asp:BoundField DataField="Interfaces" HeaderText="Interfaces" SortExpression="Interfaces" />23 <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />24 </Columns>25</asp:GridView>26 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"27 SelectCommand="SELECT * FROM [itp_Projects]"></asp:SqlDataSource>28<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"29 SelectMethod="GetCustomers" TypeName="BLL_Customers"></asp:ObjectDataSource>
File ascx 2:
1<%@. Control Language="VB" AutoEventWireup="false" CodeFile="TestWebUserControl2.ascx.vb"Inherits="TestWebUserControl2" %>2<asp:Login ID="Login1" runat="server">3</asp:Login>
Although this is not a perfect solution It basically seems to work. But: I have to determine the View State for instance of the grid, to keep its state on the page (e.g. for sorting and so on). At the moment, (of course) it disappears if i click any function of the grid.
I hope you can see what i mean.
Eyvallah ;)
greets, Jan 
  

sorry the filenames are partly wrong...but i think you can imagine the structure.

Hallo Jan:)

What I can see here that you are building a nice project management application:) Cool project, I hope you easily succeed...

Well I've checked your code and I think you are overthinking about this login control..

First of all login control has a property that when user logsin properly it simply dissapears...
Then there's loginview control that u might be interested. It has loggedIn tamplate and anonymous template that one will be visable when user is logged in and vice versa.. You can again dynamically load your controls if the user is online or not...
I may also suggest you to keep loaded your web user controls in your page and then trigger the function stored in your ascx.vb file.. I mean just an idea...
You can also keep your login control in your master file; like I said before It will dissapear when the user is loggedin...

Happy programming..:)


jepp, thanks for your reply. I already know about how to integrate a login control in an application, its just an example for an user control. The grid is currently also only an example ;) (the user controls could have been named "this" and "that") But you′re right with the aim of the app.

greets

jan


Jan,

I have almost the same situation, but slightly different...

I have LinkA and LinkB. I have two aspx files LinkA.aspx and LinkB.aspx. I simply want to enable an AJAX load into an UpdatePanel depending on which LinkButton is clicked.

My experise is in PHP and AJAX through JavaScript's HTTPRequest method. I've got it working through my JavaScript, but I'm trying to learn/migrate to ASP.NET and its AJAX capabilities. I couldn't find any tutorials on how to do this and I've been searching for days. I finally find this thread.

Do you have any suggestions on how to do this? Thank you so much for your help.

Joshua

No comments:

Post a Comment