I have a Function Which will send the emails to different recievers say Actor1, actor2 etc. Before sending the auto generated email the user should be able to edit it.
I have used a placeholder to display the autogenered email content and a textbox to add the new content.
My function looks like this
public void SendEmail(var content)
{
...
display1= actor1content;
....
....
dsplay2=actor2content;
}
Here display1 and display2 are the controls which i am putting to placeholder. Now after function execution two displays will come together. How can I make the function to make display1 to appear first and then continue function execution and again make display2 appear.
You could use an UpdatePanel to prevent a full PostBack , and a Timer to trigger an async PostBack every 5 seconds or so. When the async PostBack occurs, you could check the status of your background operation and if you need user input (eg: if the operation has completed), register a startup script to display an alert/prompt.
Related
Lightswitch HTML Client
After a query has been executed, I'm curious how to perform changes on the client immediately after. For example, i have a search box (textbox) that takes the input and passes it along to a parameterized query. On the client, i would like to set the focus back to the search box after the query has finished. I have working java script code to set the foucs, i just don't know when and where to use it. I need something like the server methods _Executed and _Executing but on the client. Is this possible?
I don't think you'll know when the query has completed, since it's done asynchronously, and by default only loads a portion of the results. Have you tried putting the javascript to set the focus in the postRender of the control associated with the search box? You can find it in the designer for the screen by selecting the control, and selecting the drop down next to Write Code.
Don't forget to use the setTimeout method to ensure the element is properly rendered before your javascript is applied. For a proper explanation refer to Why is setTimeout(fn, 0) sometimes useful?.
I used the following and it shifted focus to the button:
myapp.BrowseMyEntity.MyButton_postRender = function (element, contentItem) {
setTimeout(function () {
element.focus();
}, 0);
};
If you really want to set focus after you've deliberately called a query and it has completed, use the promise mechanism ".then(...)", for example:
screen.details.dataWorkspace.ApplicationData.MyQuery().execute().then(function (result) {
// Do whatever you want here
}
});
I have a page that is processing data. It goes through a series of 10 steps. I want the page to display a status after each step. ie. after step 1 data processing done print "Step 1 done" then after step 2 data processing done add text "Step 2 done" etc. How can I do this using only C# without hard postbacks? Or do I have to use AJAX/Javascript or page postbacks?
I've been playing around with updatepanels. One around the whole set of steps. Or an updatepanel around each step and then calling button clicks pro grammatically. The only result I can get is for all the text to display at one time at the end of processing.
I've been racking my brain and have search google endlessly. Hopefully someone out there has an idea for me. Thanks!
I'd suggest using ajax -
Server Side:
up a new action method on your server (assuming it's MVC), use this action method to query the state of the task.
public string QueryStatus()
{
return Session["progress"].ToString();
}
When the task progresses to the next step, update a variable to indicate this (in database, or session).
Session["progress"] = "Step Four";
Client Side:
Periodically call the action method and update an element on the page accordingly.
<script>
$.ajax('/Server/QueryStatus').done(function(response)
{
$('#progressElement').innerHTML = response;
})
</script>
I am using the Calendar control of ASP.NET. I need to display a pop-up form when I hover over a particular date in the Calendar control. This pop-up should display data from database.
Does anyone have a solution for this?
You should have an empty div:
<div id="popup"></div>
then bind an event to the calendar elements:
('li.calendar').hover(function(){
//make an ajax call and populate the popup div with the data
//easiest method is jquery.load(), but if you need more control use jquery.ajax();
$("popup").load('path/to/page.asp',data,function(){
$("popup").show();
});
});
Look at jquery.load() and jquery.ajax()
I dont know how asp name the date spans, check it, its very easy to detect
after getting the selector
user jQuery to add the event
jQuery('selector').hover(function(){ //or use mousemove
getPopup(jQuery(this).text()); // just send any data to detect the date
}) ;
after that you'll need to make an AJAX request in the getPopup function
you may use
jQuery.get()//or jQuery.post()
__doPostBack()//if you have update panels
//or any ajax technique xmlhttprequest,PM,...
in the response of the ajax request just draw the popup ...
hope this helps
examle getPopup function
function getPopup(date/*for example*/){
jQuery.getScript('www.myWebsite.com/pageThatDrawsThePopup?date='+date);
// getScript assuming that the return value is JS code the immediately draws the popup
// ?date = date assuming that your page takes the date as query string and get the data from the database upon this field
//dont forget to change the url
//very simple very easy ...
}
Add a CSS class to the cell containing the date that should trigger the popup. You'll need to override the DayRender event to do this.
void myCalendar_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.Day.ToString().EndsWith("7")){// Replace with your own condition
e.Cell.CssClass+= "specialCell"; //replace with your own custom css class name
}
}
Then add some JavaScript (or Jquery) to trigger the pop-up. The JQuery ajax functions provide the easiest way to get your data and populate the pop-up as per #user1225246's answer.
$(document).ready(function(){
$('.specialCell').hover(function(){
function(){//This will get called when you mouseover
alert('put your JQuery AJAX code here.');
},
function(){
alert('do any clean-up (e.g. hiding the popup if you need to) here.');
}
});
Is there any way to when you click submit on a form, as each method call within the form submit post method completes, a check box checks off to show the user progress of the next page being loaded?
No. I think the best you could do is to disable the form and make ajax calls to each "progress" action that you want the user to be aware of. Each ajax call could then update the page with whatever indicators you want. The resulting flow would look something like this:
User clicks on fake "submit" button.
Page is disabled
Ajax call to "progress" action method 1 - Update page with indicator
Ajax call to "progress" action method 2 - Update page with indicator
Ajax call to load new page.
Display new page to user
I have a page that performs a long-running task (10 to 15 seconds) in the page_load method.
I have client-side javascript code that will display a decent "page loading" animated gif to the user.
I am able to invoke the JavaScript method from the code-behind, to display the "page loading" animated gif, however, the long-running task is hanging up the UI such that the animated gif doesn't actually display until after the long-running task is complete, which is the exact opposite of what I want.
To test this out, in my page_load method I make a call to the JavaScript method to display the animated gif. Then, I use Thread.Sleep(10000). What happens is that the animated gif doesn't display until after Thread.Sleep is complete.
Obviously I am doing something incorrect.
Any advice would be appreciated.
Thanks.
Chris
Below is an example of the code-behind:
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript
(GetType(), "Javascript", "javascript: ShowWaitIndicator(); ", true);
Response.Flush();
Thread.Sleep(10000);
}
I accomplished this by placing a timer on the page. After its first tick disable it and run your task.
<asp:Timer runat="server" id="UpdateTimer" interval="500" ontick="UpdateTimer_Tick" />
I placed this within an UpdatePanel for my needs. I'm not sure what will work best for you. Then in your code behind...
Protected Sub UpdateTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
UpdateTimer.Enabled = False
' run method here
End Sub
The reason is that the Page.Load event fires before any response has been sent to the client; so any instructions for the client (such as executing your javascript) doesn't occur until the client receives the response.
So... placing the long-running task in Page.Load won't have the effect you want. This sounds like a case for using AJAX or some other form of asynchronous data-retrieval. In this scenario the page you return to the client doesn't containt he result of your long-running task--so the page itself (with it's spinner) loads quickly, then the client requests the data; when the data is ready (10-15 seconds later) you can update the DOM in the client with the results.
Following example will work for you. just place in Page Load Event.
Response.Write("<div id=\"loading\" style=\"position:absolute; width:100%; text-align:center; top:300px;\"><img src=\"http://www.cse.iitk.ac.in/users/singhroh/images/loading.gif\" border=0></div>");
Response.Flush();
System.Threading.Thread.Sleep(5000);
Response.Write("script>document.getElementById('loading').style.display='none';</script>");
I would avoid invoking your JavaScript from the code-behind.
Instead, utilize the jQuery library. You can trigger your code to be called immediately after the DOM is loaded by using the following code:
$(document).ready(function() {
//Call your JavaScript method here.
});
You'll also need to add jQuery to your page, which is a single script include from the Microsoft CDN. Add this to your markup to do this:
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>
This will call your GIF JavaScript method immediately when the page is loaded and you can eliminate your Thread.Sleep. I'm assuming your animated GIF method automatically hides the image after 10-15 seconds.
Taking it old school, you could switch buffering off. With buffering on (the default), the page is generated in it's entirity before it's sent to the client. If you switch buffering off, it's sent as it's loaded, so you can send the html to switch the loading graphic on, do your long running task, then send some javascript to switch it off.
It sounds like the Javascript onload is being displayed after the ASP onload processes. You may want to delay your time-intensive action to Page.LoadComplete - this way, your user will see the Javascript render before the intensive operation occurs.
Then, you would update the page contents as needed after the function completes.
Can you provide an example of the code?