|
AJAX Not working in Particular Masterpages -- ShadowLord --
Because we need the W3C certification for Html 4.01 Transitional, we have removed the tag <form id="form1" runat="server"> from our masterpages. This step was necessary, otherwise the validation tool complains that the form element should not be nested. In this scenario, ajaxpro.net (6.7.19.1) fails to include the 4 js needed for ajax interoperability. Thus javascript will not work correctly. Is there any workaround, for this scenario? Thanks in advance, Pier |
|
-- Mello --
The tag <form id="form1" runat="server"> is not rendered when send to the client, probably you Validate the wrong file, ti pass the validation you have to: if the page is public - Set the validator address to the page If its private (on your dev machine) - view the page in your browser - save it in html - send the page to the validator |
|
-- GeoffreySwenson --
You probably have forms on your child pages. You don't need that. The form on the master page is quite sufficient. I define a script on the master page so that I can submit the master page from scripts on child pages. I also use hidden text elements to pass action verbs back to the page if necessary. You can have any number or these hidden verbs on a page, so you can get a very fine degree of control. You can handle the postback on the master page or the child pages as you see fit. There may be minor typos in the following script since I typed it directly in (I can't test it here). <form id='MainForm' runat=server> <input id='hiddenAction' type='hidden' runat=server/> </form> <script language="javascript" type="text/javascript"> var MainForm = DocAll('<% =MainForm.UniqueId.Replace("$","_") %>'); var hiddenAction = DocAll('<% =hiddenAction.UniqueId.Replace("$","_") %>'); function SubmitForm(Action) { hiddenAction.value = (typeof(Action) == "undefined" ? "" : Action); MainForm.submit(); } //support script var bDocAll = false; if (document.all) { bDocAll = true; } function DocAll(szID) { if (bDocAll) { return document.all(szID); } else { return document.getElementById(szID); } } </script> Geoffrey J. Swenson geoffrey -----Original Message----- From: ajaxpro AJAX Not working in Particular Masterpages Because we need the W3C certification for Html 4.01 Transitional, we have removed the tag <form id="form1" runat="server"> from our masterpages. This step was necessary, otherwise the validation tool complains that the form element should not be nested. In this scenario, ajaxpro.net (6.7.19.1) fails to include the 4 js needed for ajax interoperability. Thus javascript will not work correctly. Is there any workaround, for this scenario? Thanks in advance, Pier |
|
-- ShadowLord --
Ok, Thanks for the script, but our pages heavily rely upon dhtml and forms, as we are working with old asp.net code, we can't refactor it now. However, it seems that the form is rendered even though it shouldn't: this is the testing masterpage: pay attention. the form is named form1 <%@ Master Language="C#" AutoEventWireup="true" CodeFile="GeneralAJAX.master.cs" Inherits="GeneralAJAX" %> <!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 runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:contentplaceholder id="pagecontent" runat="server"> </asp:contentplaceholder> </div> </form> </body> </html> then this is the testing page: (aspx) <%@ Page Language="C#" AutoEventWireup="true" CodeFile="testajax3.aspx.cs" Inherits="testajax3" %> <!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 runat="server"> <title>Untitled Page</title> <script type="text/javascript" src="scripts/wui.js"></script> <script type="text/javascript" src="scripts/wsel.js"></script> </head> <body> <form id="form1" runat="server"> <div> <script type="text/javascript" language="javascript"> function GetServerTime() { //alert("calling"); AJAXInterop.GetServerTime(GetServerTime_callback); // asynchronous call } function GetServerTime_callback(res) { alert(res.value); } GetServerTime(); </script> </div> </form> </body> </html> and code behind: using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class testajax3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(AJAXInterop)); } } note that the ajax part is omitted as it works. if you retrieve the page, you will notice that the aspnet form is rendered with name aspnetForm which wasn't required: <!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></head> <body> <form name="aspnetForm" method="post" action="testajax2.aspx" id="aspnetForm"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMDUyNjYzMjhkZKja5ZHDZO9y8ETy+xxM6HAkmTGi" /> </div> <script type="text/javascript" src="/WebUI/ajaxpro/prototype.ashx"></script> <script type="text/javascript" src="/WebUI/ajaxpro/core.ashx"></script> <script type="text/javascript" src="/WebUI/ajaxpro/converter.ashx"></script> <script type="text/javascript" src="/WebUI/ajaxpro/AJAXInterop,App_Code.ashx"></script> <div> <form id="aaaaaaaa" action=testajax3.aspx> <input type="text" id="ton" /> </form> <script type="text/javascript" language="javascript"> function GetServerTime() { alert("calling"); AJAXInterop.GetServerTime(GetServerTime_callback); // asynchronous call return false; } function GetServerTime_callback(res) { alert(res.value); } </script> <a onclick="GetServerTime()">Test me!</a> </div> </form> </body> </html> The validator, obvioulsy: form should be nested, Some tag can not be contained in themselve. For ex, a FORM tag in a FORM tag. for this reason we had stripped out the form. Thanks in advance, Pier |
|
-- ShadowLord --
I forgot... our website must be fully working without js, though, we try to not to have distinct design/implementation lines (one for js/ajax and the other without js. the latter couldn't be implemented having one form in the masterpage, or at least, our documentation says so. In case it is really possible, limiting the "hidden fields" on the masterpage, we may think to change our design....), but try to have them as nearer as possible.. Thanks again.. Pier |
|
-- MichaelSchwarz --
Hi, if you need a version without JavaScript you are not able to add AJAX to you web site, Asynchronous JavaScript and XML. ;) Regards Michael On 7/20/06, ShadowLord <cpier83> wrote: I forgot... our website must be fully working without js, though, we try to not to have distinct design/implementation lines (one for js/ajax and the other without js. the latter couldn't be implemented having one form in the masterpage, or at least, our documentation says so. In case it is really possible, limiting the "hidden fields" on the masterpage, we may think to change our design....), but try to have them as nearer as possible.. Thanks again.. Pier > -- Best regards | Schöne Grüße Michael Microsoft MVP - Most Valuable Professional Microsoft MCAD - Certified Application Developer http://weblogs.asp.net/mschwarz /http://www.schwarz-interactive.de /Skype: callto:schwarz-interactive MSN IM: passport |
|
-- ShadowLord --
Hi, We have found a workaround, maybe will help somebody: we have moved our code in a separate code file in the app_code folder then we added the follow lines to the master page, without the aspnetForm, Response.Write (@"<script type=""text/javascript"" src=""/WebUI/ajaxpro/prototype.ashx""></script> <script type=""text/javascript"" src=""/WebUI/ajaxpro/core.ashx""></script> <script type=""text/javascript"" src=""/WebUI/ajaxpro/converter.ashx""></script> <script type=""text/javascript"" src=""/WebUI/ajaxpro/AJAXInterop,App_Code.ashx""></script>"); this should emulate the register type for ajax. In our testing environment, it is working fine. Thanks for everything Regards, Pier |
|
-- GeoffreySwenson --
I have absolutely no respect for people who turn JavaScript off on the page. But as Michael put it, if you are using AJAX, you HAVE to use JavaScript. There is no point of even trying to use the same pages to serve JS and nonJS users IMHO. You aren't going to get much help about NOT using JS here since the J in AJAX is for JavaScript. JavaScript is pretty much the main focus of this site. If you are using ASP.net, JavaScript is used heavily on the client side by most of the various controls. If you disable JS, they don't work. So you are going to have to use html and standard controls, no asp at all (or go back to classic asp) in order to make your site work. I'm glad I don't have to deal with thoroughly stupid stuff like this on my job. Geoffrey J. Swenson geoffrey -----Original Message----- From: ajaxpro Re: AJAX Not working in Particular Masterpages Hi, I wasn't clear. Our website should work with and without js. The same pages should serve js users and non-js users. This was in reply to Geoffrey who said to leave the form element in the master page. Any suggestion for our scenario? Thanks. |
|
-- ShadowLord --
Hi, I think the same, but, we must do that. However the point was not the use of javascript, but the fact that ajaxpro.net failed to render the js code when the main form was not present in the master page. That was all. With our workaround it works the same. Thanks. |
|
-- ShadowLord --
Hi, I wasn't clear. Our website should work with and without js. The same pages should serve js users and non-js users. This was in reply to Geoffrey who said to leave the form element in the master page. Any suggestion for our scenario? Thanks. |
|
-- jmgp --
Why you don't you try this: 1. put a form tag in the beginning of your master page: <form runat="server"></form> 2. Put your another forms as you want The includes for javascript AJAXPro files will be rendered and you'll be able to call your server functions in any line of your page (using javascript). This works fine for me. I'm one of the dummies who put the ashx files by hand to work around the fact some of my pages has two or free form tags. And this approach works fine for me. |