Showing posts with label stuck. Show all posts
Showing posts with label stuck. Show all posts

Monday, March 26, 2012

probably simple but i am new - Trying to do a partial render on a master page for my navi

I am trying to learn ajax and i got off to a fairly good start but i am stuck on this one and couldnt find any answers on the net.. i understand the use of a script manager and a updatepanel i got it to work on a page with a tree and when you select a item it loads a picture into a imgbox and it works great but here is my problem

I have a master page.. on the master page it contains my navi bar. each of the 4 buttons opens a new content page (*.aspx). I am trying to set it up so the Navi bar doesnt reload everytime i open another content page.. i want just the contentplace holder to refresh.. I have tried putting a updatepanel around my navi bar but it just doesnt seem to work.. i know this is probably really simple and i want to thank everyone in advance.

Thanks

-steve

I think you were on track when u put update panel over your menu. Just make sure that the update panel UpdateMode=Conditional

This way it will only cause postback when some trigger or other method will make it to cause postback.

Here are some good tutorial on UpdatePanel and update methods.

http://www.asp.net/learn/ajax-videos/video-177.aspx <-- this one talks about conditional mode

http://www.asp.net/learn/ajax-videos/video-159.aspx

http://www.asp.net/learn/ajax-videos/video-118.aspx

Also, you can do it other way around and place an Updatepanel in your Content Holder, and set it to update based on the menu selection. This way only parts your need actually be updated in content holder.


hello.

hum, i'm not following: you're opening a new content page but you want to do that without refreshing the page presented in the browser? if that is what you want, then the answer is: cannot be done. you'll have to refactor your site so that the content is loaded through user controls. if that is not what you meant with the previous mail, please give us more information.


Luis Abreu:

hello.

hum, i'm not following: you're opening a new content page but you want to do that without refreshing the page presented in the browser? if that is what you want, then the answer is: cannot be done. you'll have to refactor your site so that the content is loaded through user controls. if that is not what you meant with the previous mail, please give us more information.

Ok.. let me try to explain it better for you..

Files:

Masterpage.master
Home.aspx
contact.aspx
services.aspx
portfolio.aspx

So all of the pages above use Masterpage.master as the master page The master page is layed like this

Top Image
Navi Bar
ContentPlaceHolder
Bottom Image

so lets say we start out at home.aspx and we want to click on the contact img (on the master page) and it goes to contact.aspx
i want to do it in a way that instead of loading contact.aspx and reloading the content of the masterpage.. it only loads the contentplace holder..

I understand what your saying but what controls would i have to use.. or maybe i set up the image the way its linked wrong i used html.. here is the code maybe i should do it another way? Now you have me really thinking.. ill tinker with it more later today but i greatly appreciate your help.. thanks


hello again.

ok, then it's option 1. i think that in this case, you'd need to refactor your site so that it only has one page. you'd need to transform home, contact, services and protofolio pages in asp.net user controls which would be loaded when you click on the menu. I've written an old post that shows how to replace the contents of an updatepanel. it might help you get starting:

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


hey Luis.. ok i started using ascx and everything works fine except for the fact that now when i load a ascx file into a contentplaceholder in a updatepanel the asptreeview that i now have as a webcontrol instead of a page wont work... any ideas? it wont let me expand anything..

Saturday, March 24, 2012

Problem adding ToolkitScriptManager dynamically

Hi All,

Please help me I am stuck and can not go ahead without resolving this issue.

I have created a post(http://forums.asp.net/p/1141711/1838544.aspx) in Asp.net Ajax Extension Discussion forum but I think for this issue this forum is more appropriate.

Our website has no of pages and I do not want to add ToolkitScriptManager in every file and I want to add it in my base page. I am trying to add ToolkitScriptManager dynamically as suggested in threadhttp://forums.asp.net/p/1039254/1777798.aspx in OnPreInit event. But I am getting exception "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)." What could be reason?

Here is code...

protectedoverridevoid OnPreInit(EventArgs e)

{

if (ToolkitScriptManager.GetCurrent(this.Page) ==null)

{

ToolkitScriptManager Manager =newToolkitScriptManager();Manager.EnablePartialRendering =true;foreach (Control cinthis.Controls)

{

if (cis System.Web.UI.HtmlControls.HtmlForm)

c.Controls.AddAt(0, Manager);

}

}

}

Here is exception

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

Line 519: if (c is System.Web.UI.HtmlControls.HtmlForm)Line 520:Line 521: c.Controls.AddAt(0, Manager);Line 522: }Line 523: }

Any idea what could resolve this issue?

Thanks, V

Hi,

As the error message indicates, there are code blocks in your page, so you can't modify Controls collection.

For instance:

<%@. 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">
public string hello = "hello";
protected override void OnPreInit(EventArgs e)
{
if (AjaxControlToolkit.ToolkitScriptManager.GetCurrent(this.Page) == null)
{
AjaxControlToolkit.ToolkitScriptManager Manager = new AjaxControlToolkit.ToolkitScriptManager();
Manager.EnablePartialRendering = true;
foreach (Control c in this.Controls)
{
if (c is System.Web.UI.HtmlControls.HtmlForm)
{
c.Controls.AddAt(0, Manager);
break;
}

}

}

}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToString();
}
</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:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
<input value=<%=hello%> />

</div>
</form>
</body>
</html>

It can be solved by assigning the input control's text in code behind.

1. Mark it as runat server

2. In page_load, add : idOfTheInputControl.Value = hello;

Hope this helps.