I have a simple ASP.NET page with an image control and a button control. When someone clicks the button, I want the image to be shown, then the button can continue processing whatever it has to do, at the end of it's process it will hide the image again.
Is this possible? I've seen conflicting answers. I've tried using just the base code behind functionality and registering javascript functions on the fly (the javascript functions execute AFTER the button has completed all of its work, not before).
Thanks - Greg.
In normal scenario in asp.net it is not possible.
But there are many other way
User Update Panel and Update Progress from ajax tool kit and use those.
Use jQuery to call server side function and show updating image while ajax is processing.
Update Progress tutorila:- http://msdn.microsoft.com/en-us/library/bb386421%28v=vs.100%29.aspx
jQuery Page Method call :- http://weblogs.asp.net/craigshoemaker/archive/2008/11/07/using-jquery-to-call-asp-net-ajax-page-methods-by-example.aspx
Jquery Ajax Loading image
Yes it is possible. You should use ajax call rather than code behind which will be more complicated. Very roughly, on click of the button in the javascript do something like this:
function handleClickEvent(e){
$("#imgId").show();
$.ajax{
make ajax call here with right parameters;
success:function(){$("#imgId").hide();
}}
First , Use JavaScript function (OnclientClick , for button ) , to show the image. and then registering javascript functions to hide it from code behind.
Related
I have a page I'm working on and it works correctly in the sense that I press a button and it executes a stored procedure. The problem is the stored procedure takes awhile to complete, and I want the user to know that there is progress being made and that it's not stuck. So is there a good method to give the user some idea of the progress being made? I was going to just simply display an animated gif, but not sure how to do this. Or if there is a more preferred way to do this I'm all ears. Thanks!
Generally it is a bad idea to have a website command take time, but when you have to Microsoft have an Ajax library which works with ASP.Net - this includes a Progress bar control which can appear when you are doing a long task
The site for the ASP.Net Ajax can be found here; http://www.asp.net/ajax
The Ajax Control Toolkit which includes the progress indicator is here; http://www.asp.net/ajaxlibrary/act.ashx
If you do an AJAX call you can use jQuery to show a loading graphic. See this post How to show loading spinner in jQuery?
Yes, you can definitely use an animated .gif to display to the user while the stored procedure is executing. You'll want to use ASP.NET AJAX to accomplish this, specifically using UpdatePanel and UpdateProgress controls.
View the following URL which guides you on implementing the UpdateProgress control: http://www.asp.net/AJAX/Documentation/Live/mref/T_System_Web_UI_UpdateProgress.aspx
The section on "Specifying the Content of the UpdateProgress Control" talks about using the ProgressTemplate to show an animated image that notifies the user of the progress on the page.
--Tyler
I know my issue is very common and similar types has been asked many times over here, but my problem is somewhat different. I am working on ASP.Net 4.0 web application where on my required page i have ajax toolkit 4 calendar control, toolkitscript manager and few asp controls. Now from that pop up i am doing a save operation on button click. What i want is to close popup window after successful save. Problem is not in saving but after saving , automatically closing the popup screen. I have tried the following ways:
RegisterStartUpScriptBlock(this.GetType,"closeForm","return window.close();") and all other required params
ClientScript.RegisterStartUpScript()--- alongwith params and with both return window.close(); and window.close() also with self.close();
Also i have under the title tag...
I think i have tried all the ways , i can. I feel i am lost. Please help me out....
if your using a script manager on the page...
first create a function to close the calendar in js in your html...
function closeCalendar(){
....
}
then on the codebehind use this to call that js function
string script = string.Format(#"closeCalendar()");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true);
If the popup you mean is the AJAX Toolkit Modal Popup, you can just call popup.Hide(); in codebehind.
If it is a browser window, did you try to remove the return part from your code?
Note that windows.close() will not work unless the popup is opened via window.open();
Also, did you try to just put the script tag inside PlaceHolder control that is hidden (server-side Visible=false) by default and only shown when you need?
I'm using Javascript to create a DIV element and open up a new page by using onclientclick. This works great. Now, I need to write to it from the server side and this element must be created before it is posted back.
How do I get the javascript to execute before the postback?
Currently, I have to press the button twice because the element doesn't exist to write too on the first click.
To be clear, I need this to execute before the "OnClick" of the button.
Update: It looks like the Javascript function is called before the postback but the element is not updated until I run the second postback. Hmm
Update: Unfortunately it is a bit more complicated then this.
I'm creating a div tag in javascript to open a new window. Inside the div tag, I'm using a databinding syntax <%=Preview%> so that I can get access to this element on the server side. From the server side, I'm injecting the code.
I'm thinking this may be a chicken-egg problem but not sure.
UPDATE!
It is not the Javascript not running first. It is the databinding mechanism which is reading the blank variable before I'm able to set it.
Hmm
you don't have to rely on server controls to perform postbacks in asp.net. you can gain finer control of your app by posting from javascript whenever you are ready..
the framework auto generates a function called __doPostback(.....) and eventually calls it every time it needs to do a postback.
so. instead of using server control button, you can have a regular <button onclick="foo()" />
than once you're done performing all that you need, just call the __doPostback function.
asp.net gives you a nifty way to access that function with
Page.GetPostbackClientEvent (i believe, but there are couple methods that support this methodology)
http://msdn.microsoft.com/en-us/library/system.web.ui.page.getpostbackclientevent.aspx
enter code hereWould this work for you?
Javascript
function stuffYouWantToDo(){
//do your stuff
//then submit the .NET form
document.forms[0].submit();
}
.NET code
<asp:button ID="Button1" onClientClick="return false;stuffYouWantToDo();"/>
This should ensure that the stuff you want to do is done, then the form will be submitted. The return false prevents the form from being submitted when you first click the button and relies on the call in the stuffYouWantToDo function to submit the form.
If you want to use jquery you could do the following:
$(document).ready(function() {
var execScript = $(".myButton").attr("href").replace("javascript:", "");
$(".myButton").attr("href", "#").click(function() {
// Add before click logic here
eval(execScript);
});
});
Couldn't you simply add a custom validator somewhere in your form?
I have an ASP button, when I click this button, first I want to run code behind progress such as data delete, update..
After this progress, I want to runJquery function related this button.
How can I do that?
Your server-side event handler can call ScriptManager.RegisterStartupScript to invoke jQuery in the browser.
If I interpret your question correctly, you want to post back to the server so you can run your code, and when you return, you want to run some jquery. Is that correct?
If so, you'll need to inject some jquery into the response after you do your work.
So your code-behind will delete a record or run an update, then write some jquery to the response which will run when the page is built on the client. You might want to use the Page.RegisterStartupScript method to do this.
An alternative is to go down the ajax route, but that's a bit more complicated.
The JavaScript prompt command
prompt("sometext","defaultvalue");
is a useful way to easily prompt the user to provide a value. But it can't really be a part of any polished web 2.0 application (The dialog looks horrible).
Is there any existing component to display a modal dialog that will prompt a user for a value? I can use a pure JavaScript solution or anything developed for ASP.NET
I'm sure there are a lot of things that fit the bill in of the most javascript frameworks out there. For instance, there are a few out there for jQuery e.g. Impromptu or if you want something specifically for ASP.NET then there are few things you could probably use from the ASP.NET Ajax Control Toolkit such as the Modal Dialog or of course, you could roll your own!
You can code your own solution with a div containing an input field and a button and some JavaScript to show/hide the div.
This will not block the JavaScript code flow so you will have to set a callback function on the Close/Ok button.
If you are ok with JS libraries almost all of them have a Dialog widget.