Calling server side function that runs in the background of my website - c#

I want to call a server side function which will run in the background of my website (while the user is navigating between the pages and continues to work normally).
I thought of writing the method in my Main.Master.cs page, call it from the client side of the content page, and display a popup at the end of the execution.
Is it possible?
How can I call Main.Master.cs method from content page client?
Thanks.

I had similar issue.
I used jQuery ajax with generic http handler returing json
I created handler and put my business logic there.
It return me the result in form of json
I iterated the json using jquery.
And created my html form that.
Edit 1
Here are some useful links
http://www.codeproject.com/Articles/203621/Call-HTTPhandler-from-jQuery-Pass-data-and-retriev
http://www.sharepointnutsandbolts.com/2010/11/sp2010-ajax-part-4-returning-json-from.html
Edit 2
You can also take benefit of jtemplate If you want to display something from the server to the page.
http://www.joe-stevens.com/2010/01/05/using-the-jtemplate-jquery-plugin-with-ajax-and-asp-net/
http://encosia.com/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/

Yes it is possible if you are using Ajax in your application.
here is a detailed article on how to do this.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109

Related

avoid autopost back asp.net

i am working on a web application using asp.net c#. it has multiple textbox controls like
TextboxA TextboxB TextBoxResult1
TextBoxX TextBoxY TextBoxResult2
i am doing some calculation on TextboxA,B,X,Y and displaying result to TextBoxResult1 and TextBoxResult2 using Ontextbox_change event.
my question is that On each calculation my page is going to refresh.i need to know how can i do this without auto post back . i don't want to use code other than c# like Ajax, java script, jQuery etc.
AutoPostback=true;
thanks in advance
You can't. The code on a view is done at render and is then static html. In order to update the information you either do what you're doing (POST back) or use ajax to post back to the controller but only update specific information instead of refreshing the entire page. You could look into Blazor, but it's still experimental and not fully released (I can't comment on it, haven't used it myself yet).

JQuery UI Modal Form Dialog Save Data To Database

I am using the JQuery UI Modal Form Dialog and trying to save the old data and new data to a database. I am using C# (backend) and ASP.NET front end. I can delete new entries, I just don't know how to save the data. I have tried searching ways to pull pull the HTML data in, but couldn't get rid of the errors. Also Wasn't sure if there was a better method? Here is my JSFiddle
function addUser() {
I need to figure out a way to get the data from the table and post it to the server.
I think what you may be looking for is web methods, it allows the jquery (client side) to call the backend (c#) and for them to interact with each other.
Check out this link for reference:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Here is a brief summary from the website:
When it comes to lightweight client-side communication, I’ve noticed
that many of you prefer ASP.NET AJAX’s page methods to full ASMX web
services. In fact, page methods came up in the very first comment on
my article about using jQuery to consume ASMX web services. Given
their popularity, I’d like to give them their due attention. As a
result of Justin‘s question in those comments, I discovered that you
can call page methods via jQuery. In fact, it turns out that you can
even do it without involving the ScriptManager at all. In this post, I
will clarify exactly what is and isn’t necessary in order to use page
methods. Then, I’ll show you how to use jQuery to call a page method
without using the ScriptManager.
I found this:
This script gets data from the table that you can then parse through.
You could then pass it into a hidden field.

What technology allows page content to change without changing the URL?

I have seen this on some survey websites. What is the C# code they use on the client side to keep the URL same, but when clicking the "Next" button, the same aspx page is maintained
without having any query string;
without any change even a character in the url; and
the grid, the data , the content, the questions keep changing?
Can anyone give a code-wise example how to achieve this?
My main query is how is this done in code-behind to change data of page and maintain same url.
Nothing simpler that a session, maintainted at the server side. Store a "current question number" in session, increment it at each succesfull postback and you have what you ask about.
Another possibility - a cookie which contains "current question number".
Both cookie and session are invisible in the query string of course.
"change data of page and maintain same url." Answer is Server.Transfer.
This method will preserve url.
The Next button may submit a form using the HTTP POST method. The form data may contain the session, question and response data. The site uses that to build a new response. Unlike a GET, a POST does not incorporate data into the URL.
Developers will typically accomplish this task by using AJAX. The basic premise behind it is that only a certain portion of the page (e.g. a grid or content area) will make a server call and retrieve the results (using Javascript). The effect achieved is that there has not been a full post back, which is why you don't see the URL or parameters changing.
It is possible to do this using jQuery, pure Javascript, or Microsoft's UpdatePanel.
oleksii's comment has some good links as well:
That's the AJAX magic. There are many JQuery plugings for this, for
example this one with a live demo. You can also program it easily
using JQuery Get or Post or any other wrapper that use XmlHttpRequest
object.

Referencing jquery variables in C# code (ASP.NET MVC)

How do I reference a jquery variable in a C# block in the view using ASP.NET MVC?
For example:
$(":input[#name='mydropdown']").change(function () {
var selection = $("#myselection").val();
pop($("#md"), <%= Model.choices[selection] %>);
});
Where the selection that is in my C# block is the same as the selection that is referred to in my jquery.
This is not possible to do. The C# code is executed before the HTML is sent to the user's browser, which is before jQuery gets loaded, which is before the variable selection has a chance to exist.
There are two approaches to work around this:
Dump all data that you care from Model.choices to a JavaScript variable; your JS code can then access that variable. This is simple and good if your data is not too large in volume.
Have the JS code make an AJAX request to the server to get whatever data it needs by passing the value of selection as a query string parameter.
Perhaps try Sharpkit plugin from jquery website:
http://plugins.jquery.com/project/SharpKit
You can't do this because of the browser (client) does not share any memory or state with the server what so ever
i.e.
the server executes the c# that renders the html and js
the browser downloads this and interprets it
the browser executes the javascript (no c#!)
I'd go with Jon's suggestion 1) as it will be more performant by negating the need for another callback to the server.
Long live ASP.NET MVC! :)

ASP.Net Creating Server Side Posting to external website with redirect

On a button click event I am required to POST to a page on an external website and redirect there. I get how to do this using a GET method
Reponse.Redirect("www.somesite.com?my=params&as=aget")
But how can I do this on as POST?
I don't want to post the entire form as this button event is called within a repeater
Depends.
If you want to post the exact input of a form you have on your site (that is, you just replicate a form the other site has), then just set the form's action to the URL you want to post to and the browser will do everything for you.
If however you want to post some values you generate on the server (perhaps based on the input from your form), I'm afraid it's not possible. You can't redirect using a POST. Redirect is GET by it's nature.
BUT you might be able to fake it by doing a POST (using something like System.Net.WebClient) and then a redirect (it depends on how the other site handles the GET - it might display the same thing that it did on the POST, or not).
One more option (for the second case) would be to to do an AJAX call to your server, which will compute the required values, then do the POST to the other server from Javascript.
You can build up the request using WebClient, adding the appropriate headers.
My inner forms don't contain the runat="server" attribute so I can do what I want. I do get this problem though ASP.Net First inner form in Server Form doesn’t POST.
Jquery is life saving in this situation. Used for one of my project and works like a charm. Give it a try : Peter Finch - Using Javascript to POST data between pages

Categories