Showing posts with label contentplaceholder. Show all posts
Showing posts with label contentplaceholder. Show all posts

Wednesday, March 28, 2012

Updating a ContentPlaceHolder with Ajax

I am working on a project which uses a MasterPage with one ContentPlaceHolder. I have a custom menu control on the MasterPage. When an item in the menu is clicked I need the ContentPlaceHolder to be updated with the requested content. I know this can easily be done using an iframe, but I'd rather stay away from iframes and like to do this with Ajax.

Basically my question is if this is possible at all. I've been trying a couple of things but without success and I think it may have to do by the way a MasterPage works.
If not possible, is there some kind of workaround for this? (without residing to iframes)

Thanks!

Hi Rino,

I tried also the same thing as you. I had a menu on my master page and an ContentPlaceHolder in my update panel. That didn't work. I think it isn't possible what you want to do.

Regards,


Unfortunately, no. It's just not how master pages and AJAX work. I just finished a post on the topic here:http://odetocode.com/Blogs/scott/archive/2007/01/03/9682.aspx


Thanks guys for clearing this up!
Would be great as a new .Net feature though :)


You can do it right now, actually, it's not that big of a deal. You don't really need a contentplaceholder for it, just a Div that you can hook into w/ javascript (giving it an ID, for example). You have your menu item click handler fire a javascript function that calls a web service and then have the onrequest complete handler fill the div with the stuff it gets back.

paul.vencill:

You don't really need a contentplaceholder for it, just a Div that you can hook into w/ javascript (giving it an ID, for example). You have your menu item click handler fire a javascript function that calls a web service and then have the onrequest complete handler fill the div with the stuff it gets back.

Paul: Yes, but this is an entirely different approach.


Understood. I was trying to offer something that might work for his application. is there a good reason you can think of to limit his app to using contentplaceholders?

No, my goal was just to point out that updating content place holders with content from a different page isn't how the technologies work together. It seems to be a common question these days, so I'm trying to clear that up.

The right way to achieve this would be to use a solution like you proposed!


ah, ok, cool. :D

It is very easy.

See my last post about "Handling events...".

Monday, March 26, 2012

Updating ContentPlaceHolder using UpdatePanel(like using frames)

Hi guys,

Is there a way to update the whole Content page without master page refreshing it self? like same effect as using frames or iframes in html.

I tried following, just simply placing script manager and wrapping ContentPlaceHolder with UpdatePanel, which didn't work.

Any suggestions?


<%@dotnet.itags.org. Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
<html>
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
<div id="main"
<div id="titleBar">Title</div>

<div id="siteMenu">
<asp:Menu ID="Menu1" runat="server" SkinID="MenuBar" DataSourceID="SiteMapDataSource1" OnMenuItemClick="Menu1_MenuItemClick">
</asp:Menu>
</div>


<div id="content">

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate
<asp:contentplaceholder id="contents" runat="server"></asp:contentplaceholder>


</ContentTemplate>
</asp:UpdatePanel>
</div>


<div id="footer">footer</div
</div
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
</form>
</body>
</html>



Sorry to say that master pages and AJAX don't work together in that fashion (seehttp://odetocode.com/Blogs/scott/archive/2007/01/03/9682.aspx).

There are lots of ways to refresh the content inside of the page using AJAX, but what you are trying to do requires the browser to load an entirely new page. :/


Thanks Scott.

I won't be wasting any more time trying to figure that one out.

Guess I am back to using good old Iframe.

Cheers

Dosa.

updating panelsize within scriptmanager

I need some help.

I have a masterpage with a scriptmanager surrounding my contentplaceholder. When I activate my defaultpage using the masterpage, the page_load reads in javascriptcode (RegisterStartupScript). This code runs at window::load(). The effect is that the size of a panel-component inside the contentplaceholder is set depending on the size of the window.

That works fine.

But when I read in the default-page again (using a button) the onload-event is not activated. That is the one of the good things in ATLAS, but it gives me a little problem: The size of the panel-control gets at new size according to the amount of data within the panel.

What do I have to do, when I want the size of panel to stay unchanged ?

I hope you understand my problem even thought my english is not the best.

hi sixtus,

I think i encountered the same problem !
the solution I found is :


<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testGbControls._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function resizeMe()
{
document.getElementById('panel').style.height = 200;
document.getElementById('panel').style.width = 200;
}

function PageRequestManagerPropertyChanged(sender, args)
{
if (args.get_propertyName() == "inPostBack")
{
if (!$object("_PageRequestManager").get_inPostBack())
resizeMe();
}
}
function pageLoad()
{
$object("_PageRequestManager").propertyChanged.add(PageRequestManagerPropertyChanged);
}
</script>
<script runat="server"
protected void btn_Click(object sender, EventArgs e)
{
this.content.Text += "ligne" + "<br> ";
}
</script>
</head>
<body onload="resizeMe()">
<form id="form1" runat="server">
<div id="panel" style="background-color:Red;overflow:scroll;width:100;height:100;">
<atlas:ScriptManager runat="server" ID="mngr" EnablePartialRendering="true" EnableScriptComponents=true >
</atlas:ScriptManager>
<atlas:UpdatePanel runat="server" ID="updpnl">
<ContentTemplate>
<asp:button ID=btn runat=server OnClick="btn_Click" />
<asp:label id=content runat=server Text="ligne"></asp:label>
</ContentTemplate>
</atlas:UpdatePanel>
</div>
</form>
</body>
</html>

the div "panel" is resize on each atlas postback
I hope this help you
Gildas

Unfortunately it doesn't solve my problem, because I am using Masterpages. Or I haven't totally understood the solution.

You can se my problem onhttp://localhost/scripts/ASP.NET/Oresund2/Vis/opslag.aspx?id=1

When the page is read the lightbrown panel has the right dimensions. When I click the Tekst-button in the panel, the panel keeps its dimensions as it should. Because the page is re-read I figure.

But if I choose Fredensborg in the Treeview (no postback I think) the dimensions in the panel is changed.

How do I solve that problem when then treeview and the panel isn't placed in the masterpage but in the aspx-file?


Sorry - the link was wrong. Here is the correct one:

https://temp.eg-gym.dk/scripts/asp.net/Oresund/vis/opslag.aspx?id=1


hi,
Is your lightbrown panel a <div> sizing by a javascript on load ?
can you post the code of your panel please

It looks like you got some good stuff going already on your UpdatePanel. My example might still help from the standpoint that I assure, using my method there, that the host control COULD always stay the same size (although it might not be obvious in the presentation because I don't enforce it).


I don't use a div but <asp:panel...>.

The code in page_load is:

If (Not ClientScript.IsClientScriptBlockRegistered("SetPanelScript"))Then

Dim sbScriptAsNew System.Text.StringBuilder

sbScript.Append("<script language=JavaScript>" & vbCrLf)

sbScript.Append("function opdater()" & vbCrLf)

sbScript.Append("{" & vbCrLf)

sbScript.Append(" var windowHeight = -1;" & vbCrLf)

sbScript.Append(" var windowWidth = -1;" & vbCrLf)

sbScript.Append(" if ( window.innerWidth ) {" & vbCrLf)

sbScript.Append(" windowWidth = window.innerWidth;" & vbCrLf)

sbScript.Append("}" & vbCrLf)

sbScript.Append(" else if ( (document.documentElement) && (document.documentElement.clientWidth) ) {" & vbCrLf)

sbScript.Append(" windowWidth = document.documentElement.clientWidth;" & vbCrLf)

sbScript.Append("}" & vbCrLf)

sbScript.Append(" else if ( document.body.clientWidth ) {" & vbCrLf)

sbScript.Append(" windowWidth = document.body.clientWidth;" & vbCrLf)

sbScript.Append("}" & vbCrLf)

sbScript.Append(" if ( windowWidth > 335 ) {" & vbCrLf)

sbScript.Append(" document.getElementById('" +Panel1.ClientID +"').style.width = windowWidth - 335;" & vbCrLf)

sbScript.Append(" }" & vbCrLf)

sbScript.Append(" if ( window.innerHeight ) {" & vbCrLf)

sbScript.Append(" windowHeight = window.innerHeight;" & vbCrLf)

sbScript.Append("}" & vbCrLf)

sbScript.Append(" else if ( (document.documentElement) && (document.documentElement.clientHeight) ) {" & vbCrLf)

sbScript.Append(" windowHeight = document.documentElement.clientHeight;" & vbCrLf)

sbScript.Append("}" & vbCrLf)

sbScript.Append(" else if ( document.body.clientHeight ) {" & vbCrLf)

sbScript.Append(" windowHeight = document.body.clientHeight;" & vbCrLf)

sbScript.Append("}" & vbCrLf)

sbScript.Append(" if ( windowHeight > 110 ) {" & vbCrLf)

sbScript.Append(" document.getElementById('" +Panel1.ClientID +"').style.height = windowHeight - 120;" & vbCrLf)

sbScript.Append(" }" & vbCrLf)

sbScript.Append("}" & vbCrLf)

sbScript.Append("window.onload=opdater" & vbCrLf)

sbScript.Append("</script>" & vbCrLf & vbCrLf)

ClientScript.RegisterClientScriptBlock(GetType(String),"SetPanelScript", sbScript.ToString())

EndIf

InTreeView1_SelectedNodeChanged I have got the advice to write the following, but it doesn't work.

Dim scriptKeyAsString ="setPanelScript"

Dim sbScriptAsNew System.Text.StringBuilder()

sbScript.Append("<script language=JavaScript>" + ControlChars.Lf)

sbScript.Append("<!--" + ControlChars.Lf)

sbScript.Append("opdater2();" + ControlChars.Lf)

sbScript.Append("// -->" + ControlChars.Lf)

sbScript.Append("</script>" + ControlChars.Lf)

ClientScript.RegisterClientScriptBlock(GetType(String), scriptKey, sbScript.ToString())

The panel is resized correct when the whole page is reread, but the size is changing when I select a item in the treeview.