Showing posts with label masterpage. Show all posts
Showing posts with label masterpage. 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 MasterPage panel from content page

Hello,

I have created a shopping cart which users can add products to within an update panel in a content page. However in the masterpage there is a 'basket' that displays how many products are currently in the basket. I need to find a way of updating this basket whenever the updatepanel in the content page is reloaded. Is this possible.

Thanks,

Curt.

Yes, create a Public Property on your Master Page and set the baskek based on this value. The value can then be updated from your content page (you can get access to the Master Page via Page.Master).


Thank you for your reply.

Could you give me some more help on how to do this as I don't have much experience with Public Properties just yet?

Thanks.


Here's a sample Public Property with a type of String:

Public Property Name()As String Get Return _NameEnd Get Set(ByVal valueAs String) _Name = valueEnd Set End Property

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.

Saturday, March 24, 2012

Upgraded to RC but the Bug lurks

Hi,

I have upgraded to AJAX RC version from AJAX Beta 2...... I have a Page that has a MasterPage and I'm building an HtmlTable at runtime and Add to an already existing Panel in this Page. This Panel is in an UpdatePanel.. It doesn't simply does a full postback and not an asyncronous one...

This seeems to be something related to a MasterPage since when done without a MasterPage it just works fine

please shed a bit of light on this... this is a bug that lurked from Beta 1.. anyone knows why...?

Thanks !

so no one knows or happened to come across it?

please!


Can you provide the source code. If there is no javascript error on page, I believe it might be something to do with the web.config. Make sure that legacy rendering is OFF in web.config.

vineetc


source code?

Panel1 is inside an UpdatePanel with a MasterPage.

Panel1.Controls.Clear();
Panel1.Controls.Add(new Template_cls().BuildTemplate(3, 3, 2));

BuildTemplate method returns an HtmlTable and adds it to Panel1.

...... the same code applied to a page without a MasterPage works fine.

In the web.config I have no legacy rendering .. doesn't exist. The Web.Config is updated with the latest release of the RC version.

Thanks!


I don't know why no-one wants to answer... possible that no-one uses MasterPages with UpdatePanels and creating controls at runtime?!....there's a bug

hmm... actually that works fine yes...maybe I didn't describe myself correctly

What you said is part of it and works fine. I'm adding a GridView control at runtime. The GridView has the "Select" commands. When I click the "Select" command it does a full postback to the server even though its under the UpdatePanel!


Thanks and sorry for not describing myself correctly.


I tried something like this and everything worked fine.

<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="panel1" runat="server">
<asp:Button ID="Button2" runat="server"Text="Button" OnClick="Button2_Click"></asp:Button>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:ContentPlaceHolder>
</div>
</form>

On Button2_Click, I add a control inside the panel.

protected void Button2_Click(object sender, EventArgs e)
{
Label lb = new Label();
lb.Text = "label";
this.panel1.Controls.Add(lb);
}

You need to verify that legacy rendering is OFF in your web.config. You might have to move up the hierarchy of your website and see if there are any web.configs where it might be on.

vineetc


So basically it makes a full postback when a GridView with "select" commands is added to an HtmlTable which in turn is added to a Panel that is under an UpdatePanel AND also when the Page has a MasterPage. It makes a full postback when you click on the GridView "select" command button. Both HtmlTable and GridView are added at runtime.

This is a very specific error, I'm sure its a bug so please check it out!!. It works well without MasterPages. I don't know whats with the GridView "Select" commands when under a UpdatePanel pertaining to a page has a MasterPage.

Thanks!!