As per Yahoo's guidelines for performance of web sites , javascripts should be combined in one to avoid extra http request , as i saw in YSlow asp.net loads 3 to 4 scripts one for MicrosoftAjax.js , one for microsoft MicrosoftAjaxForms.js & some other 2 which may tondle postbacks & client side validations , I want these 4 js to be in one.
Configuration : Windows Vista,VS 2005,Ajax v1.0.61025 My Html Page
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function fnCall() { try { var ans= Sim.Service.HelloWorld(OnMethodSucceeded, OnMethodFailed); } catch(e) { alert(e.message); } } function OnMethodSucceeded(result) { alert('a'); } function OnMethodFailed(result) { alert('b'); } </script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" ><Services> <asp:ServiceReference Path="http://localhost/ajaxtest/service.asmx" /></Services> </asp:ScriptManager> <div><input id="Button1" type="button" value="button" onclick="fnCall();" /></div> </form> </body> </html> Web Service CS. using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; namespace Sim { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class Service : System.Web.Services.WebService { public Service() { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod,ScriptMethod(UseHttpGet=true)] public string HelloWorld() { return "Hello World"; } } }
But i am getting Sim is not defined. Error. post ur comments. I have reviewed most of the forums. I am not able to clear
I am working with vs 2008 and C#. I am having a code behind function as follows(not complete)
protected void btnShowZone_Click(object sender, EventArgs e) { string setofalllatsandlongs = null; foreach (string s in ar) {
[Code].....
</div>In thIn the click event of the btnShowZone(in bold) i am calling the code behind method and from that i am trying to call the js function using the script manager class.
But the javascript method is not getting called.the control is not going to the js function.
I have a user control with both an UpdatePanel and a ScriptManager.
Some pages in the system have a ScriptManager of their own, and need to include the UserControl.
This throws the "You can only have 1 ScriptManager" exception.
If I remove UserControl's ScriptManager, I'll get 'UpdatePanel1 requires a Script Manager" exception.
I've tried to modify the UserControl to dynamically include it's own script manager if none exists. But all the methods I've used before involve adding a delegate to Page.OnInit-- which won't work, since the UserControl Init fires first.
Because the system designers here like making my life difficult, I can't create a MasterPage, or a BasePage for the system in inherit off of. I'd be stuck going to each page an adding a ScriptManager before the UserControl on each of them. Is there any way of, in the UserControl, detecting if the page has a ScriptManager, and if not, adding it dynamically in a way that makes the UpdatePanel happy?
In my global.asax file for my ASP.net project, I am checking for certain conditions. When those conditions are met, I want to automatically execute javascript code when the page runs.
This is my code:
if condition Then Response.Write(" < script type=""text/javascript"" > ") Response.Write(" // Javascript code to do stuff ") Response.Write(" < /script > ") End If
While this appears to work to execute the Javascript code, I don't think it's a best practice because this code will preceed all of the HTML of the page that gets loaded.
What is the best way of programmatically tacking on some extra Javascript code to be run when my page loads?
I click the continue button which does a post back but the values are not updated until I refresh the page again which makes me think the js isn't being run until after the page is returned. I'm wondering how to have the values updated when the page is refreshed after the button postback.
I am creating a browsergame in ASP.NET (using AJAX, jQuery, ect. - NO Flash). In this game I need to play some sound files. Right now I have those files as .WAV, but if the solution can play .MP3, that is preferred.I have several events during the game which need sounds: You hit the monster, you die, you level up, ect. The page is based upon update panels, which means I will have to add several sounds (and replay them at specific events) without a postback. As some of the sounds is replayed every 3-5th second and others are played way more rare, it has to be efficient to this requirement.What would be the best and most efficient solution to solve this? :-)
I want to run the LoadArray() function initialy when the page loads. This function is calling a pagemethod given in aspx.vb code file..
Partial Class test3 Inherits System.Web.UI.Page <System.Web.Services.WebMethod()> Public Shared Function Load_Array() As String() Dim Model_Name_old As String()() Dim mod_code As String() Dim mod_name As String() Dim cod_upper As Integer //calling webservice that retunrs a jagged array Dim ins As New localhost_insert_model.dbModel Model_Name_old = ins.get_Model_Name("A") mod_code = Model_Name_old(0) mod_name = Model_Name_old(1) Return mod_name End Function End Class
So how can i load the javascrip LoadArray() function onPageLoad in this scenario?
I don't need to run the function every time the page loads!!
But, I would like to have the control when the function is to be called.
The only way I thought of is calling my function with OnLoad in the body tag and having a hidden field to be checked and then run the script accordingly.
e.g:
<body onload="ScrollToView();">
Is there a better way? For example, running the function from Page_InitComplete handler?
We have a function that changes the iframe height at the window.onload event so we can adjust it to the page contents. The problem is that after clicking in an asp:menu the height its restored to its default and the window.onload event doesnt fire...so we need the event that would fire in subsequent loads (tried window.unload but didnt trigger)
The resize function cant be called on the asp:menu click because the window wouldnt have finished loading so the height calculation would fail...
I am trying to fire a Javascript call when an ASP.net user control to an aspx page. The Web site allows users to add user controls to a page (similar to adding a widget etc to a page like google widgets). But when the control is added the javascript does not fire, only if the page is refreshed will it fire the javascript. IF the next time the website is accessd and the controlis still there the javascript fires too.Do I need to use the RegisterClientScript method to register the call (setAutoTimer()) on the control load or OnPreRender event.In the User control I have this at the start of the ascx file:
I have an existing site having a bulk of javascript used on the page. Now the page has to convert in AJAX but while using update panel my controls are not able to use existing javascript
It is not feasible to use ScriptManager.RegisterClientScriptBlock because script is around 200 to 300 of lines and also not feasible to move it in another JS File and Use ScriptManager.RegisterClientScriptInclude since each page has different script with almost same numbers of line Is there any way so that i can use existing script with minimum number of steps with full reusability
This is the exact same question as this unanswered one from May.
(edit) Note: this unanswered post exactly describes the behavior - extra scripts being added in the <head> by ScriptManager.RegisterClientScriptBlock in a usercontrol, in an UpdatePanel, is causing duplicates. C# .NET 4.0. The page is structured like this:
MasterPage Page UserControl1 (ascx) - loaded in code by Page UpdatePanel UserControl2 (ascx) - loaded in code by UserControl1
The first time the script is added as expected, in the body. The code, simply, in the UserControl2 OnInit:
I've also tried referencing "this" instead of page, which doesn't really make sense since I don't want the same script keys duplicated on the page if the usercontrol is loaded multiple times on a page, but it didn't work anyway.
After a partial postback, the script is added again - but curiously in the <head> of the page, not the body, and interestingly, lacking the normal //<![CDATA[...//]]> wrapper that asp.net usually adds.
Another script which is added by UserControl1 is duplicated exactly the same way after a partial postback.
we're looking to compress our gargantuan JavaScript files with GZip to speed up the page loads of our site. I know this can be done through IIS, but I can't seem to find a simple step-by-step guide on how to implement it.We're running IIS7.5 on Windows Server 2008 R2.
I have an application that uses various script files. These files are not used for any AJAX purposes. However, I am using MS AJAX Libraries. My goal is to use the ScriptManager to manage release and debug versions of my JavaScript. Is this the right approach? Is there a better way to handle this task?
I am successfully including a javascript resource by calling ScriptManager.RegisterClientScriptResource at the end of OnPreRender in my custom control. However, the resulting script tag is being included before the automatically included script tags that define things like Type and Sys which my script depends on. I thought they were defined in the order that they are included but I can't include my script any later then I am. How can I control the order in which the script tags are included?
I have a jQuery function in a .js file, and the function requires a querystring parameter to be passed. If I try to use the CompositeScript feature in the ScriptManager, it pukes on the file that has the querystring.
i want to update my page from database every 20 Sec..so for that i want to pass multiple data fields from server to Client using AJAX.. what can i use for that except using xml?
I have a usercontrol that wprks fine as along as one instance is on a pageut as soon as i have two instances of it nothing works. I figured out that it could be the pageload function that adds handler for keydown and other that is the cause.As each instance is reproducing the same javascript in the viewsource.So can you tell me how can i make the usercontrol that it can have multiple nstances that have their own javascript pageload
I know how to call a simple old fashion asmx webservice webthod that returns a single value as a function return result. But what if I want to return multiple output params? My current approach is to separate the params by a dividing character and parse them on teh client. Is there a better way.
Here's how I return a single function result. How do I return multiple output values?
i have two ajax cascadedropdown combos loaded by a web service. When mi page loads, it do it before the data filled the first of the cascade combos so when page load (on the Page_load event) i try to select a value on the first combo but it is still empty. What can i do to force the load of the combos before page load? I have try combo.cascadropdwonextender.databind() on the page_load with no sucess.
I have a user control that needs a javascript function so I put my JS code in a variable and used the ScriptManager.RegisterStartupScript in Page_PreRender of the control as follows
I have a form which I am using the RoundedCornersExtender, If I am using the ScriptManager control I am getting the following error-Error: AjaxControlToolkit requires ASP.NET Ajax 4.0 scripts. Ensure the correct version of the scripts are referenced. If you are using an ASP.NET ScriptManager, switch to the ToolkitScriptManager in AjaxControlToolkit.dll.I googled it and found that one way to overcome this is to use the ToolkitScripyManager, I replaced the ScriptManager with the ToolkitScriptManager and I dont get the above error anymore. On this same form I am using an UpdatePanel control but from some reason I am not getting a partial render but always a full page render.