I have a button in aspx. In its onclientclick I called a javascript function which is written in JScript.js.
Following is my javascript:
function ChangeBG()
{
alert("hi");
}
I called this above function in button click. I had put breakpoint in javascript. But onclicking on button, alert is coming, but control is not going to breakpoint. What may be the reason for this? I am running in Internet browser. What change i can make to bring the focus to breakpoint. Can anybody help?
Before alert("hi"); put the stmt debugger;
ChangeBG()
{
debugger;
alert("hi");
}
Your control will come to debug when you are in debug mode. This problem occurs when javascript is in a separate js file.
Also do this to enable debugging in your IE browser
Go to
Tool-->Internet Options-->Advanced
Uncheck - Disable script debugging ( Internet Explorer )
Related
I have a button inside a update panel, & I am using jQuery scripting to style the elements in the page. Initially the page loads & css style applies on it along with the script which have some jQuery code. i.e. Initially everything is OK. But when I click on the button it causes a server post-back(necessary), the CSS style is applied but Script is not loaded. Please help me out with this.
Add this to your script (if using .Net 3.5 or less). It will notify the Microsoft Ajax Library that the JavaScript file has been loaded.
if (typeof (Sys) != 'undefined')
{
Sys.Application.notifyScriptLoaded();
}
Note: This is obsolete in .Net 4
You need to run your code (best as a named function) as part of the endRequest event as well, for example you can have a named function like this:
function doStuff() {
//do whatever here
}
Then run that function where needed:
//run on DOM ready
$(doStuff);
//also run it when UpadtePanels finish/reload
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(doStuff);
when my application launches in the IE from start page to main page i want to hide the addressbar and the standardbuttons bar of IE through the codebehind and here am using masterpage concept so i have to write the code in master only i think so....can anyone help for this
AFAIK you cannot disable address bar and button in IE from when the application starts unless using some ActiveX, Flash, ... Only if your application opens new window popups you could hide them.
I just found a way... It works atleast in IE 7... Not sure about other browsers...
<html>
<head>
<script>
if (window.name == 'default') {
window.name = 'Hai';
window.open('main.html', '_self'); // Current html file name
}
else if(window.name == '') {
window.name = 'Hai';
window.open('main.html', '_self'); // Current html file name
}
else if(window.name == 'Hai') {
// Use your application startup page here along with the desired options
window.open('newfile.aspx','NEWWINDOWNAME', 'Status=0, location=0');
window.close();
}
</script>
</head>
<body>
This window automatically closes itself
</body>
</html>
The complete list of options are available here.
Hope this helps.
Explanation : (AFAIK) Generally when javascript uses window.close method to close the active window, IE will ask for a confirmation from the user. Such confirmation will not be asked when the window is a popup window opened previously by a javascript along with a name.
The above just fakes the same, by opening the same file in the same window but this time with a name. As a result when window.close is executed, IE recognises the current window as a window opened using Javascript and as it also has a name, it just closes the same without confirmation.
Of course, I get a general Javascript alert at the beginning of the load, but since (I presume) you will be using aspx or other types, this problem will not be there.
I'm using hotkeys (Ctrl+key) in my flex application. getting problem when my app is running in IE.
when I press Ctrl+D, im getting 'Add a Favorite' window of IE.
How should I override the default behaviour of the browser? if possible, give me some example.
In your event handler, try
event.returnValue = false;
See this SO thread: event.preventDefault() function not working in IE
I have a usercontrol with a couple of drop downs Lists and a button, I want the user to click the button (Which response.redirects depending on the selection in the DDL's).
Now instead of redirecting straight away, I want to display a little loading icon for 3 seconds and then redirect... Has anyone done anything like this?
An artificial delay where none is needed is kinda lame. What you can do instead is on submission of your form display your throbber. I use the following on a document upload form where large media files are being posted.
<script type="text/javascript" id="PreJavaScript">
function NUsubmit(){
document.getElementById("uploadFormInputs").style.display = 'none';
document.getElementById("progressBar").style.display = 'block';
return true;
};
function init() { document.getElementById("UploadFormObject").onsubmit = NUsubmit; };
window.onload = init;
</script>
If I remember correctly, in some versions of IE the animated gif didn't play but it worked fine in IE6+ and FireFox.
This way if the postback is quick they never see the throbber but if it takes a while they see it and it gives them the sense that something is happening.
You can perform delays with the setTimeout() function in javascript.
setTimeout(function() { alert('After 5 seconds.'); }, 5000);
You're probably going to need to override a couple things in your Javascript and use a "setTimeout" to delay the loading.
<script type="text/javascript" >
var __handleSubmit = theForm.submit;
theForm.onsubmit = function() {
alert('loading'); //Show your message here
window.setTimeout(function() {
__handleSubmit();
}, 3000);
}
</script>
You might want to play with a bit more... this is may not work for all instances since I've never done it.
If the delay is simply for "aesthetics", to make it appear it is working, then I'd recommend against it - programmers appear to be the only people that think loading bars are cool :)
Looks like you should implement this page using AJAX. You can place a progress indictor on your page to alert the user that a long running process is taking place.
I got this working by using
System.Threading.Thread.Sleep(4000);
In the postback
I have the current problem, let's explain the context before :
I have a Modal popup extender who contains a form. There is a feature "Save and Add New", when the user click on this button the data in the form is saved in the database during postback and the page is reloaded.
I want this Modal popup to appear again on the page_load allowing the user to enter new data without clicking again on the button who show this Modal Popup.
I've tried to call it this way first :
ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "ShowModalPopup(""" & Me.formModalButton.ID & """);", True)
but the problem was when the function was called my Modal Popup was not existing yet on the page. Because of that the code was crashing on the
var modal = $find('myModal');
So, I found that other way and it's working almost perfectly.
ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(function() {ShowModalPopup(""" & Me.formModalButton.ID & """)};", True)
The modal is showing up on the page load like I want, but the problem is if I click on any other button on my page the Modal Popup is also appearing again.
Example : I have another Modal Popup for deleting data, when I click on the button, both Modal are appearing, which is not cool.
Does anyone have a clue about how to fix that or a better way to do it ?
P.S. I'm not calling to Modal popup server-side because the javascript function exist in the page, so I don't want to create a copy of this function in the RegisterStartupScript.
Thx for your time.
Use the below code snippet
//Declares gloabal variable
ClientScript.RegisterStartupScript(Page.GetType(),"vardeclaration","var reloadModal;",true);
ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(
function()
{
reloadModal = function() {ShowAddModalPopup(""" & Me.imgAdd.ID & """);};
Sys.Application.add_init(reloadModal);
}
);", True)
This would allow you to use
function cancelClick()
{
Sys.application.remove_init(reloadModal);
}
Finally I found a workaround for my current problem.
I'm still using the ClientScript.Resgister[...] but this time I also change the OnClientClick Javascript function of my cancel button.
So when the guy select the feature "Save and Add New", when the page reload and the modal Show again if he click on Cancel I do a postback to the server just to reload the page and solve those weird behavior.
I also think, the problem could exist because of the different Update Panel in my code, but I need them to make the Modal Popup Extender working.
Anyway, I discovert that's it's not even working in Opera and Safari, but the Whole thing (Ajax Control toolkit - Modal popup extender).
It's a chance the compagny here don't care about the other and support officially only IE. In my case, I wanna make it works at least in FF and Chrome too.
ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(function() {ShowAddModalPopup(""" & Me.imgAdd.ID & """)});", True)
btnCancel.OnClientClick = "resetDefaultValue();__doPostBack('" & btnCancel.ID & "','onclick')"
So there is the code, also in FF another error appear,
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 0
And I found this workarounf for it, it's not the best but I lost enought time with this...
ClientScript.RegisterStartupScript(Page.GetType(), "WorkAroundFF", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest); function endRequest(sender, args) { /* Check to see if there's an error on this request.*/ if (args.get_error() != undefined) { $get('Error').style.visibility = ""visible""; /* Let the framework know that the error is handled, so it doesn't throw the JavaScript*/ alert. args.set_errorHandled(true); } }", True)
So thx for your help Ramesh, i'm pretty sure your solution would work if it was not my Update Panels.
Hope that could help someone else.