how to set timeout for progress bar script - javascript

<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
//Raised before processing of an asynchronous postback starts and the postback request is sent to the server.
prm.add_beginRequest(BeginRequestHandler);
// Raised after an asynchronous postback is finished and control has been returned to the browser.
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
//Shows the modal popup - the update progress
var popup = $find('<%= modalPopup.ClientID %>');
if (popup != null) {
popup.show();
}
}
function EndRequestHandler(sender, args) {
//Hide the modal popup - the update progress
var popup = $find('<%= modalPopup.ClientID %>');
if (popup != null) {
popup.hide();
}
}
</script>

i got solution.
set timeout AsyncPostBackTimeout="50000" in ToolkitScriptManager or ScriptManager

Related

cross domain issues prevent action when reload parent page

I'm trying to reload the parent page from another domain. I achieved the reload on parent page when closing the child, but once I reload, the action on onclick event triggers again. My question is how can I prevent window.open once it reloads?
This is the code:
// here I've added `return false` but it fails to prevent the popup
<asp:HyperLink ID="HyperLink1" runat="server" onclick="return myopen('https://www.example.org/applicant/getdrivers?ApplicantId=15647&type=0', 'VieworUploadDocs','toolbar=no,location=no,directories=no,status=no,menubar=no,position=center,width=700px,height=850px');return false;" Text="Click Here" />
The script:
<script type="text/javascript">
//open window
var myWindow = null;
var myTimer = null;
myopen = function (url) {
myWindow = open(url, 'VieworUploadDocs', 'toolbar=no,location=no,directories=no,status=no,menubar=no,position=center,width=700px,height=850px');
myTimer = setInterval(function (e) {
if (myWindow == null || myWindow.closed) {
alert('Please wait while page loads.');
location.reload();
clearInterval(myTimer);
e.stopPropagation();
}
}, 5000);
}
</script>
I've also tried putting this in my code:
return false;
e.preventDefault();
e.stopPropagation();

Calling a jquery function in code using vb.net

having a bit of an odd problem, the situation is a bit unique in that I want to show/hide a div in instances both server side and client side, as such I cant change it to a panel.
The current code I have to change its visiblity client side, which works, is:
$('#<%= txtSurname.ClientID%>').on('input', function hideControl() {
var current = $('#<%= txtSurname.ClientID%>').val();
var surname = $('#<%= hdnSurname.ClientID%>').val();
if (current == surname) {
$('#pnlReason').hide()
console.log('hiding');
} else {
$('#pnlReason').show()
console.log('showing');
}
});
When a user clicks a button, the page validates, and refreshes, and the panel is rendered invisible again. As such I want to run this code again on the page load so that if the two variables are still different when the page validation is run, the panel is still visible. This is what im using to call it serverside:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "ShowHide",
"$(document.ready(hideControl()));", True)
When I try running it however, it says that hideControl is undefined, any ideas whats going wrong?
you could reorganise your jquery like this and once the page is refreshed, you can execute your function at the end of the document ready without the need for RegisterStartupScript():
//shorthand for document.ready
$(function () {
var hideControl = function() {
var current = $('#<%= txtSurname.ClientID%>').val();
var surname = $('#<%= hdnSurname.ClientID%>').val();
if (current == surname) {
$('#pnlReason').hide()
console.log('hiding');
} else {
$('#pnlReason').show()
console.log('showing');
}
}
$('#<%= txtSurname.ClientID%>').on('input', function () {
hideControl();
});
//call it at end of ready function:
hideControl();
};
Since hideControl is defined as anonynous function you can't access it. You have to define the function hideControl outside of the on event handler. Put the function within the script tags in the page not in a separate file:
<script>
function hideControl() {
var current = $('#<%= txtSurname.ClientID%>').val();
var surname = $('#<%= hdnSurname.ClientID%>').val();
if (current == surname) {
$('#pnlReason').hide()
console.log('hiding');
} else {
$('#pnlReason').show()
console.log('showing');
}
}
</script>
Then call the function like that at server side without the parenthesis:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "ShowHide",
"$(document.ready(hideControl));", True)

Click on control cause unwanted JS call

I have an unexpected behavior of two JS which get called when I click on a control.
These JS are supposed to be called only when the button in the Tree list is clicked under specific conditions.
Right now the JS "message alert" is called even if a click on any of the node of the tree list when the conditions apply.
The other JS, which open a window, also opens when a node of the tree list is clicked, but after having opened and closed it at least one time.
protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
{
string idMessage = "";
if (e.CommandName == "Select")
{
if (e.Item is TreeListDataItem)
{
TreeListDataItem item = e.Item as TreeListDataItem;
idMessage = item.GetDataKeyValue("MessageID").ToString();
}
}
addMessage(idMessage);
}
private void addMessage(string idMessage)
{
if (Label1.Text =="" || Label1.Text==null )
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('You shall be logged-in to post and replay to messages');", true);
}
else
{
{
Session["fatherMessageID"] = idMessage;
string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(ShowWindow);</script>";
ClientScript.RegisterStartupScript(this.GetType(), "showWindow", script);
}
}
}
Function which opens the window:
function ShowWindow() {
var oWnd = window.radopen('Window1.aspx', 'window1');
}
Function which close the window from inside the window:
function GetRadWindow() {
var oWnd = null;
if (window.radWindow) oWnd = window.radWindow;
else if (window.frameElement.radWindow) oWnd = window.frameElement.radWindow;
return oWnd;
}
function CloseWindow() {
var oWnd = GetRadWindow();
oWnd.close()
}
Function which calls the CloseWindow inside the window page:
finally
{
string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(CloseWindow);</script>";
ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", script);
}
How can I fix this issue?
Alert Issue:
you need to place addMessage(idMessage); inside if (e.Item is TreeListDataItem) condition
Dialog Issue:
not sure whether window.radopen('Window1.aspx', 'window1') is correct or not. if you are using RadWindow then showwindow function should be something like this var oWnd = window.radopen(null, "[RadWindowID]");

Disable button in update panel on async postback

I have multiple update panels with various asp buttons on a single page. I want to disable the buttons which caused the postback in update panel untill it completes.
Is there a way to avoid using a third party control for this? through JQuery or any other method ?
You can either do this:
cs
//in pageload
//the request is not in postback or async mode
bt1.OnClientClick = "this.disabled = true; " + ClientScript.GetPostBackEventReference(bt1, null) + ";");
Note: you can replace "this.disabled = true" with a js function that will have better handling for disabling the button and maybe display a friendly message as well.
Or this:
http://msdn.microsoft.com/en-us/library/bb383989.aspx
js
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);
function CheckStatus(sender, arg)
{
var postBackElement = arg.get_postBackElement();
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm.get_isInAsyncPostBack() && postBackElement.id == "btn1") {
arg.set_cancel(true);
//display friendly message, etc
}
}
Note: I modified it so it checks for the button's id. Replace "btn1"
Good luck!!
You can use the start and stop message of the update panel to disable your controls.
For example
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
function InitializeRequest(sender, args) {
document.getElementById("ButtonToDisable").disabled = true;
}
function EndRequest(sender, args) {
document.getElementById("ButtonToDisable").disabled = false;
}
</script>

How to verify that the link was clicked using onbeforeunload function in javascript

I am trying to write an integration test using onbeforeunload function, where I click on the image and it launches the url page on the next tab. I need to verify that after the click, new tab was launched. With the script below, it returns false.
if (somename === 'complete') {
var content = document.getElementsByTagName("someframe")[0].contentWindow;
var unloadFlag = false;
window.onbeforeunload = function (e){
unloadFlag = true;
}
var imageClick = content.document.getElementById("imageLayer")
imageClick.click();
assert(unloadFlag === true, "unloadFlag is false");
}

Categories