Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Wednesday, March 28, 2012

pageLoaded event

I have created an ASP.NET custom server control that is updated using AJAX via an UpdatePanel using the Tick event of a Timer control as the asyc trigger. I need to execute javascript each time a partial postback returns so I am using the pageLoaded event. This works perfectly in IE7 but doesn't fire in Firefox 2.0.0.3 or Opera 9. On other browsers it never fires the pageLoaded event, but it does the AJAX updating and other javascript works. I am registering the client code during my control's render method.. I have also tried using the endRequest event. Please help. Why won't it work on other browsers.

Below is the rendered HTML:<!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><title>Untitled Page</title><meta content="text/html;charset=iso-8859-1" http-equiv="content-type" /><meta content="NO-CACHE" http-equiv="PRAGMA" /><meta content="NO-CACHE" http-equiv="CACHE-CONTROL" /><meta content="0" http-equiv="EXPIRES" /><style type='text/css'> a.info:active{z-index:0; position:relative; background-color:#FFF647} a.info label{display: none} a.info:active label{ display:inline; position:absolute; white-space:normal; text-wrap:normal; word-wrap:break-word; left:label.parent.width; top:label.parent.height; width:250px; border:1px solid #91907C; background-color:#EAE7C6; z-index:-1; } </style> </head><body> <form name="form1" method="post" action="Default.aspx" id="form1"><div><input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMzQxMTA4OTkPZBYCAgMPZBYCAgEPZBYCAgIPZBYCZg9kFgJmDxYGHgtjZWxscGFkZGluZwUBMB4LY2VsbHNwYWNpbmcFATAeBXN0eWxlBSlwYWRkaW5nOjVweDt6LWluZGV4OjIwO3Bvc2l0aW9uOmFic29sdXRlO2RkMUSTfpjSwghJETl9/Jgkha9oZaA=" /></div><script type="text/javascript"><!--var theForm = document.forms['form1'];if (!theForm) { theForm = document.form1;}function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}// --></script><script src="/WebResource.axd?d=9DvoInn8tlftzCiBPvQagg2&t=632974035101093750" type="text/javascript"></script><script src="/ScriptResource.axd?d=WAnysv6JNp-Tgl_8AndGJnGXdfOUUPdccvGwkhkSJu2uP8RLi_go1jCrdTe0jCpJF0u8GYhfCflHcjQdOJTaXMeB6qn3C9aitPrPuScmgSM1&t=633063657262888841" type="text/javascript"></script><script src="/ScriptResource.axd?d=WAnysv6JNp-Tgl_8AndGJnGXdfOUUPdccvGwkhkSJu2uP8RLi_go1jCrdTe0jCpJF0u8GYhfCflHcjQdOJTaXOmCYkHGf_k8diSD9UcMEoc1&t=633063657262888841" type="text/javascript"></script><script src="/ScriptResource.axd?d=WAnysv6JNp-Tgl_8AndGJnGXdfOUUPdccvGwkhkSJu2uP8RLi_go1jCrdTe0jCpJF0u8GYhfCflHcjQdOJTaXLsHgXZk2LxHv8oSN-rIGKs1&t=633063657262888841" type="text/javascript"></script> <span id="events" style="font-size:Small;"><span id="events_timer1" style="visibility:hidden;display:none;"></span><input name="events$ctl00" type="hidden" id="events_ctl00" /><div id="events_UpdatePanel1"><table cellpadding="0" cellspacing="0" style="padding:5px;z-index:20;position:absolute;"><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/greenshd.gif" alt="The IT Road Show.........................." /></td><td style="padding-left:5px;">Tuesday 24 Apr</td><td style="padding-left:15px;">3:30 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="http://www.nova100.com.au" id="events_3160" EventsEventDatesId="3160" LabelId="events_label_0_3160" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The IT Road Show.......................... </a></td></tr><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/AKMAL_OVER.gif" alt="The Akmal Show" /></td><td style="padding-left:5px;">Tuesday 24 Apr</td><td style="padding-left:15px;">4:00 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="#" id="events_2749" EventsEventDatesId="2749" LabelId="events_label_1_2749" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The Akmal Show <label id="events_label_1_2749" style="text-decoration:none;">The Akmal Show with Kate Richie Weekdays 4pm-6pm.Akmal was born in Egypt - then moved to Australia. Akmal's mum doesn't think he's that funny - now the rest of Australia think he's ha haa hilarious.</label></a></td></tr><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/greenshd.gif" alt="The IT Road Show.........................." /></td><td style="padding-left:5px;">Wednesday 25 Apr</td><td style="padding-left:15px;">3:30 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="http://www.nova100.com.au" id="events_3161" EventsEventDatesId="3161" LabelId="events_label_2_3161" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The IT Road Show.......................... </a></td></tr><tr><td rowspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-bottom:5px;padding-top:5px;"><img src="../images/AKMAL_OVER.gif" alt="The Akmal Show" /></td><td style="padding-left:5px;">Wednesday 25 Apr</td><td style="padding-left:15px;">4:00 pm</td></tr><tr><td colspan="2" style="border-bottom-style:None;border-bottom-color:#91907C;border-bottom-width:thin;padding-left:5px;padding-bottom:5px;"><a href="#" id="events_2750" EventsEventDatesId="2750" LabelId="events_label_3_2750" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">The Akmal Show <label id="events_label_3_2750" style="text-decoration:none;">The Akmal Show with Kate Richie Weekdays 4pm-6pm.Akmal was born in Egypt - then moved to Australia. Akmal's mum doesn't think he's that funny - now the rest of Australia think he's ha haa hilarious.</label></a></td></tr><tr><td rowspan="2" style="padding-bottom:5px;padding-top:5px;"><img src="../images/redshd.gif" alt="test add 25" /></td><td style="padding-left:5px;">Thursday 26 Apr</td><td style="padding-left:15px;">2:29 pm</td></tr><tr><td colspan="2" style="padding-left:5px;padding-bottom:5px;"><a href="k" id="events_136" EventsEventDatesId="136" LabelId="events_label_4_136" onfocus="document.getElementById('events_ctl00').value = this.LabelId" onblur="document.getElementById('events_ctl00').value = ''" class="info">test add 25 </a></td></tr></table></div></span> <script type="text/javascript">//<![CDATA[Sys.WebForms.PageRequestManager._initialize('ctl06', document.getElementById('form1'));Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tevents$UpdatePanel1'], ['events','events$timer1'], [], 90);//]]></script><script type="text/javascript"><!--Sys.Application.add_init(function() { $create(Sys.UI._Timer, {"enabled":true,"interval":1000,"uniqueID":"events$timer1"}, null, null, $get("events_timer1"));}); Type.registerNamespace('EventsManager'); var prm = Sys.WebForms.PageRequestManager.getInstance(); if (prm != null) { prm.add_endRequest(pageLoadedHandler); } function window.onload() { } function pageLoadedHandler(sender, args) { var hidden = document.getElementById('events_ctl00'); if (hidden != null) { var labelId = hidden.value; if (labelId.length > 0) { var lbl = document.getElementById(labelId); if (lbl != null) { lbl.parentElement.setActive(); } } } } Sys.Application.initialize();// --></script></form> </body></html>

Below is my code for the Render method when I used the endRequest event:

protected override void Render(HtmlTextWriter writer) {base.Render(writer);//Add script and register it. Page.ClientScript.RegisterStartupScript(typeof(EventsManager),"script", @dotnet.itags.org." Type.registerNamespace('EventsManager'); var prm = Sys.WebForms.PageRequestManager.getInstance(); if (prm != null) { prm.add_endRequest(pageLoadedHandler); } function window.onload() { } function pageLoadedHandler(sender, args) { var hidden = document.getElementById('" + ClickedLinkLabelId.ClientID + @dotnet.itags.org."'); if (hidden != null) { var labelId = hidden.value; if (labelId.length > 0) { var lbl = document.getElementById(labelId); if (lbl != null) { lbl.parentElement.setActive(); } } } } ",true); }

Hi,

Can you show me a stripped version of your control and a sample page using it?

It will be easier for us to trouble shooting. Thanks.


Hi Raymond,

I really appreciate your offer of help, but I just figured out what the problem was.

My javascript code below was causing a problem for all the code in my script block on all browsers apart from IE.

Problem code:

function window.onload()
{

}

When I changed it to the code below, it worked in all browsers.

Correct code:

window.onload = function()
{
document.getElementById('" + TimeZoneOffset.ClientID + @."').value = -(new Date().getTimezoneOffset());
}

Thanks again.

Monday, March 26, 2012

PageMethods is undefined

Hi there

I have a simple page that calls a server side page method via the scriptmanager / page methods detailed on this site. This has worked fine recently when until I updated our dev team to use the new asp.net ajax 1.0.

Once I'd updated my web.config as per the doco all works fine on my pc but on all others when I call the server side method I get the client script error " PageMethods Is 'Undefined' ". I am sure this is an environmental issue but I would appreciate any tips on how to figure out what is going on!

To update one of the boxes (eg our test server) I did the following steps.

    Uninstall previous ASP.net Ajax (RC1)Install new versionUpdate web.config as per instructions in the doco

Here is my source code

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="AddNote.aspx.cs" Inherits="controls_AddNote" EnableViewState="true" %><%@dotnet.itags.org. Import Namespace="System.Web.Services" %><!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>Add a note to this cell</title> <link rel="stylesheet" type="text/css" href="../css/calumo default.css" /> </head> <body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0"> <script type="text/javascript" language="javascript"> function PageMethodCall() { var TicketId=parseInt($get("inpTicketId").value); var DataSource=$get("inpDataSrc").value; var Catalog=$get("inpCatalog").value; var Cube=$get("inpCube").value; var DataPointMdx=$get("inpMdx").value; var NoteValue=$get("taNote").value; if(NoteValue.length>0) PageMethods.SendNote(TicketId,DataSource,Catalog,Cube,DataPointMdx,NoteValue,OnSucceeded); } // This is the callback function // that process the page method call // return value. function OnSucceeded(result) { // Display the result. if(result==1) window.close(); else alert("Calumo Server Exception:-" + result); } function Validate() { if($get("taNote").innerText.length>0) $get("btnSend").value="Send"; else $get("btnSend").value="Close"; } </script> <form id="frmAddNote" runat="server" target="_self"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <input runat="server" type="hidden" id="inpTicketId" value="" /> <input runat="server" type="hidden" id="inpDataSrc" value="" /> <input runat="server" type="hidden" id="inpCatalog" value="" /> <input runat="server" type="hidden" id="inpCube" value="" /> <input runat="server" type="hidden" id="inpMdx" value="" /> <table id="Table1" runat="server" height="100%" width="95%" cellpadding="0" cellspacing="0"> <tr id="trHeader" > <td><img alt="" src="../images/Calumo/top_bar.jpg"/></td> </tr> <tr><td> </td></tr> <tr id="trBody"> <td id="tdNoteArea" align="center">  <textarea cols="10" runat="server" style="height:100%;width:650px;" id="taNote" rows="10" ></textarea> </td> </tr> <tr><td> </td></tr> <tr id="trFooter"> <td style="padding-right:20px;width:100%" id="tdClose" align="right"> <input id="btnSend" type="button" value="Send" onclick="javascript:PageMethodCall();" /> </td> </tr> </table> </form> </body></html>

and here is the server code

 [WebMethod()]public static string SendNote(int TicketId,string DataSource,string Catalog,string Cube,string DataPointMdx,string NoteValue) {try {// Add a note to the server code and return a sample msgreturn"It Works"; }catch(Exception ex) {return ex.Message; } }

Any hints on troubleshooting would be greatly appreciated

Thanks in advance

Graham

Try settingEnablePageMethods="true"

<

asp:ScriptManagerID="ScriptManager1"runat="server"EnablePageMethods="true">

Yep thats it! Would probably be a good idea to add to the update doco

thanks


Was that missing in the documentation somewhere? We'll happily fix it... just point me to where it's missing.


There should probably be a section on Page Methods...in the docs that is accessible by the left hand side index..

Also, for whatever reason - the UpdatePanels UpdateMode is set by default to "Always" a special highlight in the docs should indicate this is the default and to change it to conditional for partial rendering / asynchronous updates. I was kinda surprised when investigating some of the post and issues on always full postbacks - that when I just dragged and dropped an updatepanel in designer - it defaulted to "Always"... kinda missing the purpose I think as if you are releasing this - then the default should err on side of the Ajax technology it is supposed to provide and this is a change I think from the RCs but not positive as I always declare everything anyways... but alot of folks just drag and drop and assume they are getting the settings for exploiting the Ajax enviroment...


I followed this docohttp://ajax.asp.net/documentation/Migration_Guide_RC_to_RTM.aspx

and unless I skipped over it I didn't find any reference to the EnablePageMethods

thanks again


I agree! Where can you find reference and documentation to PageMethods ? I use the block of code on this post as my reference right now ..


http://ajax.asp.net/docs/tutorials/ExposingWebServicesToAJAXTutorial.aspx

I agree this would be nice to see in the "differences" docs. I'll see if it can be added.


Just wanted to say thanks, all.

I was trying to get a method to run from a page (both in the .aspx file and in the code behind) and kept getting the js error of "PageMethods" not found. Adding that attribute to the ScriptManager cured the problem.

Pete.

Wednesday, March 21, 2012

Partial rendering and #id css selectors problem

I noticed that if use partial rendering, IE6.0 removes styling information that was applied for an element via #id-of-element css selector. Is there a workaround? I know there are plenty of ways to apply a style to an element, but this one is pretty useful. I'm working with April CTP of Atlas.

Thanks

This bug affects FireFox as well. I've opened a bug report on the feedback center:
http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=b2a2bbe9-9312-4f63-adae-2e77e056ca06