I inherited some code that uses ASP.NET AJAX pageLoad client side event.
The code runs fine and the method is called when the page is opened in the server in an URL such as http://localhost/IISApp/page.aspx, but when I open it in the server with URL http://ServerName/IISApp/page.aspx, the pageLoad is not called.
Any idea on what may be causing the behavior? This happens in Firefox and IE.
Update:
The pageLoad is in a separate file, and is declared as
function pageLoad(sender, args)
{
....
}
This file is included in the master page as:
<asp:ScriptReference Path="~/js/functions.js" />
It's running is IIS7, there are no special configurations in IIS for when a user hits the site with server name or localhost. If I run it from VS 2010 (Cassini web server), the method is also not being called.
Thx in advance
You need to add a script manager to your aspx page,
or you can add the following script to the page head
document.body.onload=pageLoad;
regards
Related
I run the application through web tabs and my site loads in iframe.
The first page contains the files:
https://live.zwidgets.com/js-sdk/1.0.5/ZohoEmbededAppSDK.min.js and my custom file app.js.
His code:
ZOHO.embeddedApp.on("PageLoad",function(data)
{
console.log(data);
})
ZOHO.embeddedApp.init();
everything is fine here. The "PageLoad" event is running.
After a certain business logic I redirect the page location.href="some url of my site". This page contains the files: https://live.zwidgets.com/js-sdk/1.0.5/ZohoEmbededAppSDK.min.js and my custom file app-second.js. This file contains the same code:
ZOHO.embeddedApp.on("PageLoad",function(data)
{
console.log(data);
})
ZOHO.embeddedApp.init();
but the "PageLoad" event does not occur. Why?
The "PageLoad" event is executed only once? At the first opening of Zoho CRM?
We can understand that the method pageload is not executed after you have performed the page redirection.
Unfortunately, Zoho object wont be resolved in the other pages and it will be available only in the page which you have registered in the developer console.
We follow Single Page Application approach, so it won't be possible for you to retrieve CRM information in other pages.
As a workaround you can hide and show different sections based on your business logic.
I am really a fresh guy for asp.net. I am using Visual Studio 2012.
I'm creating a login page, were there are two buttons Login and Exit.
When i click the Exit button then application have to be close and also stop the debugging.
My try: referred
I know there are other solutions on the given link for this problem but i prefer the following approach.
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();");
}
and written the following javascript function within the Login.aspx.
<script language="javascript" type="text/javascript">
function CloseWindow() {
window.close();
}
</script>
Note: The above script works fine if i click on exit button but application also get close when i click Login button and also debugging is not getting stop.
Your page is doing exactly what you asked it to do.
In your Page_Load, you called:
ClientScript.RegisterOnSubmitStatement()
That method causes every form submission to execute the script you provided; that means all of your buttons will run your CloseWindow procedure when they are clicked.
If you only want one of your buttons to close the window, then you should only attach the CloseWindow method to one of them. The answer you selected from the linked question only works because there's only one button on the form. I'd recommend you go with one of the other answers, e.g. using:
OnClientClick="javascript:window.close();"
as an attribute on your Exit button.
Handle the two buttons separately. Do whatever you want with the login button to submit the page and handle the postback but don't tie any events to the CloseWindow() function. Then, simply create and handle the Exit button like:
<input type="button" onclick="CloseWindow();" value="Exit"/>
The easy answer for your note is to use Internet Explorer as the default launch browser in the debug toolbar.
Unlike a winforms application, an ASP.Net application is stateless. The code that runs in the browser is not dependent on the same resources as the code that is running in the Visual Studio debugger. The only connection between them are the requests that the browser makes to the server (VS 2012 debugger either treats itself as a server or uses IISExpress) and the responses that the server sends back as part of those requests.
In most cases, this means that, when you close the browser, the server keeps on going, waiting for more requests. Internet Explorer works a little differently than the other browsers with Visual Studio. When the IE instance that Visual Studio launches gets closed, the debugger process also closes.
If you really are just starting out the ASP.Net, you should try the ASP.Net MVC framework. It has a cleaner separation between server and client side code, which may help you avoid some of these types of issues.
Suppose that we have a website called example.com
In this website we have a single button which when clicked runs a javascript function let's say myFunction()
Is it possible to create an http request from the url bar of firefox so that when this http request is finished, the button would be clicked as well?
For instance, it would be good if I could include this url to the url bar of my browser
example.com + javascript:myFunction()
which would run the function after loading the page without having me to click on the button
however this does not work for me.
thank you in advance
Nope, that's not possible.
You can't append JS in a url. You can however use JS instead of a url, so javascript:myFunction()
You can use window.onload:
window.onload = function() {
myFunction();
}
as soon as the URL has loaded myFunction will execute, but unless some kind of bad server side logic is used, you can not tell a page to execute some arbitrary JavaScript after it has loaded without the page knowing of it.
I am writing a chrome extension that injects a div into a website with a content script. The content script makes an AJAX request to a website that I cleared in the manifest.json file and it inserts the data into the div with innerHTML. Part of what the AJAX request returns is javascript that needs to be executed. The AJAX request from within the content script works fine.
When I make the same AJAX request from a regular website, the javascript that is returned executes just fine, but when I make the AJAX request from the content script it does not execute. No errors are displayed in the console. I don't want to reload the website, if possible.
I assume that this is a security 'feature' and not a bug. How can I turn off or circumvent this behavior?
First off what Rob W said is very important, if you don't already know it, a good explanation of the different environment a content script runs in is useful.
You might want to check this out. It's not 100% what you're looking for but the main part is there. Basically from your background page (if you don't have one already create one), you use chrome.tabs.executeScript() to execute the script you've downloaded. That runs the javascript in the real page context instead of the "content script" context. All you need now is to get that script (in string form) to the background page, and determine the tabId to execute it on (from the sender tab)
You can use chrome.extension.sendMessage to send it to the background page, and in the background.js, use chrome.extension.onMessage to receive the message with your script. From there use the sender argument to get the tabId (sender.tab.id), and build your executeScript call.
One more helpful hint, page scripts (dynamic javascript executions) in chrome by default don't show up in any set way in the chrome debugger, but you can append something like this to the string of your javascript:
"\n//# sourceURL=/myFolder/myDynamicJavascript.js"
This will make this script always show up with the "/myFolder/myDynamicJavascript.js" path for the chrome debugger, allowing you to set breakpoints in the js code you've inserted. It's a lifesaver.
I am trying to add a script reference to the script manager in the event of a Microsoft AJAX Partial Postback, ie a user clicks on a link in an Update Panel.
ScriptManager.RegisterClientScriptInclude(Page, Page.GetType(), "UniqueName",
Page.ResolveUrl(scriptPath));
Doesn't work and either does
ScriptReference script = new ScriptReference(scriptPath);
MyScriptManager.Scripts.Add(script);
From what I have read on the net, RegisterClientScriptInclude should work even in a partial postback.
http://www.codeproject.com/KB/ajax/addingCssJsAjaxPartialPos.aspx
Can anyone give any ideas why these don't work, or another way to do it?
EDIT: Additional information.
I am working with a very large legacy code base that has the forms and script manager in each page rather than in the master page. I would like to place the code into a class and use the following call to add the javascript effect.
ClientSideScripts.BackgroundColourFade(Page, ScriptManager, Control);
The reasons I want to include the script in the method call is
Consumes of the method don't have to remember to include the script
Changing the script used only requires a change in one place
Only include the javascript when needed to keep the load time of the page down
Have a look at this SO-Question because it answers your question:
ScriptManager.RegisterClientScriptInclude does not work in UpdatePanel
function dynamic() {
alert('dynamic');
$('#divDyn').text('Dynamic!');
}
// notify that the script has been loaded <-- new!
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();