Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Wednesday, March 28, 2012

pageLoad() javascript function

I understand that a script with the pageLoad() function is a way to hook into the client side load event.

That works great if you are working in the .aspx page itself. What if you're in a user control and want something to hook into the pageLoad() event on the client?

I could use Page.RegisterClientScriptBlock() to inject the JS into the page, but that would overwrite any other function that might be in the master page, content page or other user controls.

Isn't there a way to just add an event to the page load on the client side and not worry about conflicting with other code?

Thanks,

John

Can you give an example of what you're trying to do?


I'm not sure I understand your problem, but if your user control inherits from Sys.UI.Control it's initialize method will be called when the page loads.

You can add your own pageLoad() handler by usingSys.Application.add_load().


HI,

I could use the page_load server event, but that would delay the rendering of the entire page until this process is complete. The effect I am looking for is to render a page so the user has something to look at. Then, when theclient on_load event fires, initiate some long running tasks that can take place while the user already has something to look at.

Thanks,

John


Sys.Application.Load is the client side event, not server side. Take a look at the documentation I linked. That's the event that pageLoad() calls implicitly.


Hi,

In the User control , write this function ,
<script>
function IAMIntheUserControl(object,eventArgs) {
}
</script>

register this script with RegisterClientScriptBlock.

Sys.Application.add_load( IAMIntheUserControl );

PageMethods is not defined - Modal Popup

Just upgraded from RC1 to the RTM copy of AJAX and found everything is working for me (with the normal changes to the AutoCompleteExtender) except for my modal popups.

When I attempt to use the client side java script, I get a javascript error:

"PageMethods is not defined."

Here is my JavaScript code:

function myModalPop(regID){ $get("hidRegID").value = regID; PageMethods.popModal(regID, Add_Complete, Add_Timeout, Add_Error);}

and the code behind is:

[System.Web.Services.WebMethod]public static string[] popModal(string regID) { gcmControl DSsend =new gcmControl(); DataSet dsMet =new DataSet(); dsMet = DSsend.gcmDS(dsMet,"SQL","dbAll","SELECT * FROM dbo.tblFinRegister WHERE regID = '" + regID +"' AND clubID = '" + clubID +"'","tblFinRegister"); DataTable tblFinRegister = dsMet.Tables["tblFinRegister"]; DateTime dtRegDate = Convert.ToDateTime(tblFinRegister.Rows[0]["regDate"]);string regDate = dtRegDate.ToString("d");string payeeID = lookupPayee(Convert.ToInt32(tblFinRegister.Rows[0]["payeeID"]));string chartID = tblFinRegister.Rows[0]["chartID"].ToString();string regNumber = tblFinRegister.Rows[0]["regNumber"].ToString();string regPayment;if (tblFinRegister.Rows[0]["regPayment"].ToString() =="0.00") { regPayment =""; }else { regPayment = tblFinRegister.Rows[0]["regPayment"].ToString(); }string regDeposit;if (tblFinRegister.Rows[0]["regDeposit"].ToString() =="0.00") { regDeposit =""; }else { regDeposit = tblFinRegister.Rows[0]["regDeposit"].ToString(); }string regRecon = tblFinRegister.Rows[0]["regRecon"].ToString();string regMemo = tblFinRegister.Rows[0]["regMemo"].ToString();return new string[] { regDate, payeeID, chartID, regNumber, regPayment, regDeposit, regRecon, regMemo }; }
Any suggestions would be fantastic.The way the Toolkit calls page methods is such that no changes are necessary from ASP.NET AJAX RC to 1.0. However, if you're using the ASP.NET AJAX PageMethods wrappers, they made a breaking change such that you now need to set EnablePageMethods=true on your ScriptManager in order to call PageMethods like it seems you're doing above.

PageMethods in UserControl

Sorry if this has been asked before, but the search on the forum does not appear to be working. Everything returns "no results" even a search on "atlas"Smile [:)].

Anyway, is it possible to have web methods in a usercontrol and call them from javacript. I have successfully implemented the PageMethods.SomeMethod from a page but not from a User Control.

Anyone know how to do this?

Thanks,

Joe

No, PageMethods on user controls are not supported.


Will PageMethods be supported the future. I was planning on using PageMethods in controls, to me this would make sense to have.

Thanks.

hello.

i'm tented to say that it won't happen...though i might be wrong...


If there is some callback functionality that you need to use on different pages throughout your site, the best way forward would be to use the asmx web service model. This is much easier than it sounds, and the tutorial is great.

This model is more efficient than PageMethods, where ASP.NET has to initialise a Page instance from viewstate/http to get access to the method you need.

It seems to me that UpdatePanel and PageMethods have been included primarily because of ease of integration into existing sites. If you have the time to optimise, however, then the web service model is the way to go...

Cheers,
Carlos
Hi, thanks for the informaiton. can you send me an example how to use webservice model with user controls..

PageMethods call - Authentication Failed.

Hello,
I am working with RC1 and am having problems calling a pagemethod. It keeps telling me Authentication failed. 
My page is using a master page where the Scriptmanager is declared. As you can see I am using a ScriptmanagerProxy on my main page.
The code works fine when forms authentication is not on and everything else on the site works fine when Authentication is on except Ajax pagemethod calls.
Authentication is occurring on my login in page and all of the Athentication is builtinto the codebehinds. My Question. Do I have to implement
Sys.Services.AuthenticationService to be allowed to call an Ajax web service call or pageMethod call when usingFormsAuthenication?
 Here is an incomplete example of what I am trying to do. Missing the login page
// java script file test.jsfunction pageLoad(sender, eventArgs){ PageMethods.TestThis("bar",onTestComplete, OnTestFail);} 
function onTestComplete(result){ alert(result);} function OnTestFail(error){ alert(error._message)}
// code behind[WebMethod]public static string TestThis(string name){return"foo " + name;}
 
<!-- web config --><system.web><authentication mode="Forms"><forms name="test" loginUrl="Login.aspx" protection="All" timeout="60" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="true"/></authentication><authorization><deny users="?"></deny><allow users="*"/></authorization></system.web><!-- html page --><asp:ScriptManagerProxy id="ScriptManagerProxy1" runat="server"> <SCRIPTS> <asp:ScriptReference Name="PreviewScript.js" Assembly="Microsoft.Web.Preview> <asp:ScriptReference Path="Scripts/test.js" ScriptMode="Debug"'> </SCRIPTS> <SERVICES> </SERVICES></asp:ScriptManagerProxy>
"Debug"'>Can someone please help me??
"Debug"'>Thanks in advance. 
"Debug"'> 

Ok, Im gonna guess that its probably becasue the pageMethod has to be defined as static, if so is there a workaround?

Or are pageMethods totally useless in site with forms authentication?


Try changing your pagemethod's WebMethod attribute to be: [WebMethod(Session=true)]. That should help w/ the authentication issue.

Monday, March 26, 2012

PageRequestManagerParserErrorException in Firefox 2

Hi,

My website is using Ajax with UpdatePanel which is working well in IE 7. However, I keep getting the PageRequestManagerParserErrorException when I am testing it in Firefox 2. I am currently using the AJAX Beta 2. I also check to make sure there is no Response.Write while the page is postback. But the error keep poping up in Firefox. Does any know a solution for this?


Many thanks.


hello. can you biuld a simple demo page that reproduces this?

Mine does the same thing. I have Release Canidate. If I refresh the page the error goes away. If you hold your mouse over a button that has a hover event it flashes and you have to click at just the right time. The cursor blinks in the field that has focus as well andt he tab key didn't work. Not sure if I can figure what part to post but I will let you know what I find out.

Good luck

Saturday, March 24, 2012

PageRequestManagerServerErrorException with error code 500

I am working on an ASP.NET AJAX web application. I got a PageRequestManagerServerErrorException with error code 500 every time when I try to populate a text box with a string contains some HTML tags (like <BR> for example). The full error message "Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500" appears in an alert box from javascript.
The main problem is that every next async post back generates the same error on the client side. Of course, I can check the passing string preliminarily, but my question is:
Is there a way to handle an error like this so the web application continues to run?
I have already check to clear error in Application Context on Application_Error event with Context.ClearError(), but it does not affect.

Hi!,

That exception is a callback exception and the PageRequestManager is the AJAX ScriptManager control.

You could customize the callback errors using the AsyncPostBackErrorMessage property of the ScriptManager.

Also, if you want to handle the error on server-side, use the ScriptManager_AsyncPostBackError event.

Please refer to this:http://support.microsoft.com/kb/193625

Check this articlehttp://blog.g9th.com/2007/01/14/unable-to-validate-data-at-systemwebconfigurationmachinekeysectiongetdecodeddata.aspx

Let me know if you need more info.
You can also see this thread for more help:http://forums.asp.net/t/1115331.aspx


Hi chetan.sarode!

Thank you for your post.

Yesterday I tried to handle this error on ScriptManager_AsyncPostBackError event, but unfortunately it doesn't fire.

The only one event I found to handle is Application_Error on Global.asax. I could ClearError in current HttpContext, but it doesn't affect on client side. The error still apears after every next async post back (the only difference is that alert box in javascript with the error message doesn't appear).

So, is there a way to prevent the response from the server to the client in that case. I mean it is better for me, the server sends nothing to the client instead of an error that stops every next async post back.

I appreciate any advice.

Thanks again.


I will look into that more...

Will let u knowSmile


Hi,

I got the same error a few days ago.

The following is my code that got the error:

<%@. Page Language="C#" %>

<%@. Import Namespace="System.Xml" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.IO" %>
<!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 Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();

//string strxml = "<books><book>asp</book><book>asp1</book><book>asp2</book></books>";
string strxml = HiddenField1.Value;//.Replace("begin", "<").Replace("end", ">").Replace("slash", "/");
//DataSet myDS = new DataSet();
//XmlTextReader xtr = new XmlTextReader(new StringReader(strxml));
//myDS.ReadXml(xtr);
//DropDownList1.DataSource = myDS;
//DropDownList1.DataValueField = "book";
//DropDownList1.DataTextField = "book";

System.Xml.XmlDocument sa = new System.Xml.XmlDocument();
sa.LoadXml(strxml);
System.Xml.XmlNodeList saa = sa.GetElementsByTagName("book");
DropDownList1.DataSource = saa;
DropDownList1.DataValueField = "InnerText";
DropDownList1.DataTextField = "InnerText";

DropDownList1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">
// <!CDATA[

function Button2_onclick() {
document.getElementById("HiddenField1").value = test.XMLDocument.xml;
// var a = "";
// while(document.getElementById("HiddenField1").value != a){
// var a = document.getElementById("HiddenField1").value;
// document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("<","begin");
// document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("/","slash");
// document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace(">","end");
// }
document.getElementById("Button1").click();
}

// ]]>
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList><div style="visibility: hidden">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
<input id="Button2" type="button" value="button" onclick="return Button2_onclick();" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<xml id="test">
<books>
<book>asp</book>
<book>asp1</book>
<book>asp2</book>
</books>
</xml>
</form>
</body>
</html>

I resolved it by changing the code into the following code:

<%@. Page Language="C#" %>

<%@. Import Namespace="System.Xml" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.IO" %>
<!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 Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();

//string strxml = "<books><book>asp</book><book>asp1</book><book>asp2</book></books>";
string strxml = HiddenField1.Value.Replace("begin", "<").Replace("end", ">").Replace("slash", "/");

//DataSet myDS = new DataSet();
//XmlTextReader xtr = new XmlTextReader(new StringReader(strxml));
//myDS.ReadXml(xtr);
//DropDownList1.DataSource = myDS;
//DropDownList1.DataValueField = "book";
//DropDownList1.DataTextField = "book";

System.Xml.XmlDocument sa = new System.Xml.XmlDocument();
sa.LoadXml(strxml);
System.Xml.XmlNodeList saa = sa.GetElementsByTagName("book");
DropDownList1.DataSource = saa;
DropDownList1.DataValueField = "InnerText";
DropDownList1.DataTextField = "InnerText";

DropDownList1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">
// <!CDATA[

function Button2_onclick() {
document.getElementById("HiddenField1").value = test.XMLDocument.xml;
var a = "";
while(document.getElementById("HiddenField1").value != a){
var a = document.getElementById("HiddenField1").value;
document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("<","begin");
document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("/","slash");
document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace(">","end");
}
document.getElementById("Button1").click();
}

// ]]>
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList><div style="visibility: hidden">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
<input id="Button2" type="button" value="button" onclick="return Button2_onclick();" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<xml id="test">
<books>
<book>asp</book>
<book>asp1</book>
<book>asp2</book>
</books>
</xml>
</form>
</body>
</html>

For more information,seehttp://forums.asp.net/t/1126640.aspx(embedded xml datasource)

Thanks

Paging Bullet List Extender

I am trying to use PagingBulletedListExtender in my Project (VS 2005). When I used the demo data which was around 500 records it was working fine. But now when I have tried to connect bullet list control with more than 13000 records it has hanged. I am not surprised with this as I understand that this is a huge amount of data and no matter what application will hang. I wish there could be some way where we can get only that data which is required. One of the problem with Paging bullet list control is that the header bullet (A - B-C-D-E...) doesn't get generated till thhe time there is no corresponding data (which is a good thing in other sense). We solved this problem by getting all the records for first bullet and one record for rest of the bullet points, so this way we have specific amount of data. But I was surprised after that I could not find any other event which gets called when user has clicked the header bullet that is A-B-C-D-E-F-G........ If I could find this event I can always pass the bullet which user has user clicked and get the rest of the data. There is click event which is fired when we click any of the items in the bullet list control.

The only solution to my problem which I thought was to create two bullet controls. One for showing the alphabets and another for showing the data. I do not require the Paging Bullet control now. But I am really surprised that there is no event related to this or may be I was not able to find it. No I have to re-do this part again.

It would be really great if there is a event and some one can suggest that OR for the next version we can add this event.

Thanks,

Archna

Hi Archna,

Please create an item for this feature requesthere. So that it can be noticed by our product group.

Please also post the item's URL in this thread so that it may help others. Thanks.

PagingBulletedListExtender not working anymore

After Beta 2 installation PagingBulletedListExtender is not working anymore, just creates one long bulleted list. And more, notorious error 'SYS is undefined'. All changes suggested in the migration to Beta2 guide done.

"Sys is undefined" almost always means ASP.NET AJAX isn't installed correctly. If the following from its release notes doesn't help, please follow up in one of the other ASP.NET AJAX forums:

* A new ScriptResource handler has been added that requires the following entry in the Web.config
file:

<add verb="GET"
path="ScriptResource.axd"
type="Microsoft.Web.Handlers.ScriptResourceHandler"
validate="false"/>

This handler requires an entry in the Web.config file. If the entry is missing, you might see the
following error:

'Sys' is undefined.


ScriptResource handler was added to web.config
Please reply with acomplete, simple, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

<%@. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Paging Bulleted List</title>
<link href="http://links.10026.com/?link=StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>

<ajaxToolkit:PagingBulletedListExtender ID="PBLE1" runat="server"
TargetControlID="BulletedList1"
ClientSort="true"
IndexSize="1"
Separator=" - "
SelectIndexCssClass="selectIndex"
UnselectIndexCssClass="unSelectIndex" />

<asp:BulletedList ID="BulletedList1" runat="server" DisplayMode="Text" DataSourceID="mySqlDataSource" DataTextField="CompanyName" DataValueField="CustomerId">
<asp:ListItem>Blur</asp:ListItem>
<asp:ListItem>Brand</asp:ListItem>
<asp:ListItem>Color</asp:ListItem>
</asp:BulletedList>

<asp:SqlDataSource ID="mySqlDataSource" runat="server" EnableCaching="true"
ConnectionString="<%$ ConnectionStrings:NorthWindConnectionString %>"
SelectCommand="SELECT CustomerId, CompanyName FROM customers" >
</asp:SqlDataSource>

</div>


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

=================

Web.Config :

...

<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="Microsoft.Web.Script.Services.ScriptHandlerFactory, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>
</handlers>
...


I removed the SQL and code-behind dependencies from the sample above and tried it in the SampleWebSite directory of the 61126 Toolkit where it appears to work fine to me:

<%@. Page Language="VB" AutoEventWireup="true" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Paging Bulleted List</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <ajaxToolkit:PagingBulletedListExtender ID="PBLE1" runat="server" TargetControlID="BulletedList1" ClientSort="true" IndexSize="1" Separator=" - " SelectIndexCssClass="selectIndex" UnselectIndexCssClass="unSelectIndex" /> <asp:BulletedList ID="BulletedList1" runat="server" DisplayMode="Text"> <asp:ListItem>Blur</asp:ListItem> <asp:ListItem>Brand</asp:ListItem> <asp:ListItem>Color</asp:ListItem> </asp:BulletedList> </div> </form></body></html>

Yes, it works. The problem was in my Web.config

I added before ScriptResource to the handlers of the section system.webServer, and now I added this ScriptResource to the httpHandlers of the system.web section.

Now it works perfect. Thank you.

Wednesday, March 21, 2012

Parallel Asynchronous Calls to Webservice

I'm working on a dashboard / portal system that makes use of asp.net ajax to populate the contents of the dashboard objects (dashlets, or portlets). In my javascript page load event handler, I make an asynchronous call to a web service, specifically a webmethod which returns the HTML/XML necessary to render the contents of the dashlet.


What I have is effectively the following (in pseudocode for simplicity):

on page load {

dashlet1 = service.renderFunction(dashletId1, ... );
dashlet2 = service.renderFunction(dashletId2, ... );
dashlet3 = service.renderFunction(dashletId3, ... );

...

}

However, while the page does render in an asynchronous fashion, these calls are made in sequence, so the dashlets are populated in sequence, rather than in parallel.

Is there a way to have these calls made concurrently, such that each dashlet isn't effectively waiting on the previous dashlet to have been rendered before making its own asynchronous call to the webservice? Will I have to resort to threading?


Thanks in advance for any guidance.

The problem is that browsers will only fire off two asynchronous calls at any given time. There is a good article written by the PageFlakes guy on CodeProject that detailed this issue and good design for asynchronous client-side calls:

http://www.codeproject.com/Ajax/aspnetajaxtips.asp

Hope this helps!


That's great to know - I'll read up on this article.

Thanks for the link!


have you ever been able to find a solutions for this issue? I'm facing same problem, and the artcile did not seem to help, I have only two requests, and still the first request blocks the second request completly.

Tamer


I worked around it using the CNAME hack. See more here:

http://ajaxian.com/archives/using-cnames-to-get-around-browser-connection-limits

There is no "solution" to the problem, it's an inherent limitation of current gen browsers. It's strange that you have two requests and one is being blocked. Are you sure there isn't a third call in progress?

parameters in a query string to a cascading combo box...

hi all.. i have 3 combo boxes working with the cascading extender.

the problem i facing is that the first combo data depends on an item from the query string...

since now the method is a web method, i dont have access to the querystring, (i can write the code, but it always returns nothing)...

any idea how can i catch this value? for the trace i made that's the only problem i'm having with it...

Might you be able to save the relevant information on the server in the page/session state and access it there from your web method?


hi there.. i don't understand what you mean...

Hi,
By save the relevant information on the server, means that instead of passing the value in the querystring, you could for example save what you need into a session variable (Session.Add("VariableName", Value) ... and then access it in your webservice...

 <WebMethod(EnableSession:=True)> _Public Function GetContent(ByVal contextKeyAs String)As String Dim TranslationAs String =""Dim langNbAs Integer = -999Try If (Session("ParamLang2") IsNotNothing)Then langNb =CInt(Session("ParamLang2"))End If Catch ExAs ExceptionEnd Try . . . . . . . . end function

well.. that's a good idea..

Thanks :)

Partial Page rendering Issues with AJAX 1.0

The partial page rendering is not working on the new release.Is anybody facing the same problem? what could be the reason ?

The EnablePartialRendering property is by default true. inspite of explicitly setting it to true also, the partial page rendering seems to be not working.

The parial rendering works fine in the RTM of ASP.Net Ajax 1.0, I have no problem with it. Can you be more specific what you are doing, maybe show some code, because if you have a ScriptManager on the page and not turn off partial rendering, it should work, but it depends on what attribute you have enabled on th UpdatePanel and how you use it etc. By default if you drag out a ScriptManager and UpdatePanel, the UpdatePanels content will be updated when a control inside the UpdatePanel do a postback (depends if you have several child controls etc inside the updatepanel, in that case it may not always be an update).

Partial Page Render not working with Master page

I have a child page using partial page rendering and the web controls are created programmatically. Ajax seems to have a problem with control ID naming when you create your web controls dynamically. When I run this it gives me an object instance error indicating the named control "Lable1" doesn't exist.

Has anyone else run into this problem?

Is there a work around?

Master Page

<%@dotnet.itags.org.MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.master.cs"Inherits="MasterPage" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:contentplaceholderid="ContentPlaceHolder1"runat="server">

</asp:contentplaceholder>

</div>

</form>

</body>

</html>

CS child page

<%@dotnet.itags.org.PageLanguage="C#"MasterPageFile="~/MasterPage.master"Title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server">

<scriptrunat="server">

protectedvoid Page_Load(object sender,EventArgs e)

{

UpdatePanel up1 =newUpdatePanel();

up1.ID ="UpdatePanel1";

up1.UpdateMode =UpdatePanelUpdateMode.Conditional;

Button button1 =newButton();

button1.ID ="Button1";

button1.Text ="Submit";

button1.Click +=newEventHandler(Button_Click);

Label label1 =newLabel();

label1.ID ="Label1";label1.Text ="A full page postback occurred.";

up1.ContentTemplateContainer.Controls.Add(button1);

up1.ContentTemplateContainer.Controls.Add(label1);

Page.Form.Controls.Add(up1);

}

protectedvoid Button_Click(object sender,EventArgs e)

{

((Label)Page.FindControl("Label1")).Text ="Panel refreshed at " +DateTime.Now.ToString();

}

</script>

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

</div>

</asp:Content>

Create your controls in the Page_Init vs the Page_Load method.

-Damien


Damien -

I tried creating the controls in the Page_Init and it still will not work. The referrence to the control is still null. Is the page lifecycle timing wrong with the Button_Click event?


Try refering your control with:

YourUpdatePanel.ContentTemplateContainer.FindControl("YourControlName")


I don't have access to the UpdatePanel at design time.


UpdatePanel.ContentTemplateContainer.FindControl("controlName")


Thank you. Seems to work referencing the UpdatePanel "up1". Although you must instantiate "up1" as global. Simple but necessary.

Partial page refresh on master pages

Hi

I need some help. I'm working on a web site and i'm having problems to avoid a full page refresh when i navigate across the site using a menu control.

I use a master page to define the main aspect of my site. On the master page i placed a menu control and i want to refresh only the content place holder with the content page each time the user click on a menu item. I' ve tried to do this with ajax but until now, no luck.

If someone have a clue on how to do this i would very much appreciate it..Big Smile

Master pages are not frames...each time you click a link, you are on a new page, and the masterpage just gives it the same look. The only way that I have heard of to do that is with iFrames or having one page and load all your pages as user controls, although both methods are rather hacky.


I've alse tried to use iframes inside the master page and set the target property on the menu control to the iframe, but instead of loading the content page inside the iframe it opens a new window.

I placed the iframe within the content place holder on the master page. Maybe its not the right place to put it.


I think that you may need to do it on an aspx page, and all the pages you go to from there would need to not have a master page. Actually if you are doing it that way, you may not even need a master page. You could probably have a page that looks like the master page, but has an iFrame where the content template would be. I am not completely sure if that would work correctly though because we don't worry about that much though because most our pages act as separate applications, so there is not a lot of switching pages. Postbacks can also serve as a way for the user to see that they are going somewhere else, which works the way our site is, but may or may not for you.

Partial postback in IE7 and Firefox but full postback in IE6

I have a peculiar problem with ajax page not working the same way on IE6 (service pack 2) and on IE7 and Firefox…

IE7 and Firefox works perfectly and I have no complains but whenever I tried to run the page from other computers on the network (with IE6.0) the edit controls and listboxes blink when there is a partial postback which led me to suspect that maybe there is a problem with the java script and full postback is being performed.

I have not posted the code for the page because it's rather generic. I have Tab Control from ajaxtoolkit on the top of the page that switches panes with various edit boxes and list boxes and other common controls. And there is also a timer control within the update panel that triggers updates once a while (10s).

One last thing to note is that I have a listbox tool tip feature done in javascript that is also not displaying right or should I say at all except for some weird stuff sort of showing on the screen - a white outline of sorts of the tooltip. And this is all for IE6.0. Firefox is also not displaying the tooltip but that's not conerns the project since it is directed to work under IE.

Like I said IE7 (and somewhat Firefox) work perfectly…

Any help is appreciated.

Thanks,

Arek

I guess you're just experiencing typical IE6 flickering. If you have "Check for newer versions of stored pages" set to "every visit" you should set it to something else. The problem may still be there though.

Partial rendering issue with AJAX

I have following code working fine with ATLAS with partial rendering in IE and Firefox. But after I move the app to AJAX beta 1.0, it causes the the whole page rendering with Firefox 2.0 but it works fine with IE 6.x.

function setID(myID)
{
opid = document.getElementById ('<%=txtMyID.ClientID%>');
opid.value=myID;
document.getElementById('<%=ibtnMyButton.ClientID%>').click();
}

The page looks like:

<asp:UpdatePanel ID="UpdatePanel1" RenderMode="Inline" UpdateMode="Conditional" runat="Server">
<ContentTemplate>

<asp:UpdatePanel ID="UpdatePanel2" RenderMode="Inline" UpdateMode="Conditional" runat="Server">
<ContentTemplate>

<asp:TextBox ID="txtMyID" runat="server" ></asp:TextBox>

<asp:ImageButton ID="ibtnMyButton" runat="server" ImageUrl="../Images/go.gif"></asp:ImageButton>
........

</ContentTemplate>
</asp:UpdatePanel>

</ContentTemplate>
</asp:UpdatePanel>

How to solve this issue?

Try to change your codes as the following.
<asp:UpdatePanel ID="UpdatePanel1" RenderMode="Inline"ChildrenAsTriggers="false" UpdateMode="Conditional" runat="Server">
<ContentTemplate>
<asp:UpdatePanel ID="UpdatePanel2" RenderMode="Inline"ChildrenAsTriggers="false" UpdateMode="Conditional" runat="Server">
<ContentTemplate>
<asp:TextBox ID="txtMyID" runat="server" ></asp:TextBox>
<asp:ImageButton ID="ibtnMyButton" runat="server" ImageUrl="../Images/go.gif"></asp:ImageButton>
........
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
Wish the above can help you.
Thank you, Jasson, It works.