Server side method call using __DoPostBack by method name
Whenever I see this question, I get a little nervous that the searcher doesn't quite understand the full implications of triggering a response, so I want to cover them briefly:
- The browser's current DOM instance has been destroyed. As far as the browser is concerned, you submit the current page and request a complete new one.
- Not only does the server-side method execute, but the rest of the page's lifecycle, including mandatory data binding or page / page load code. Everything will be remodeled from scratch.
Is this really what you want?
source to share
Take a look at the different ways ASP.Net handles AJAX functionality or callbacks for a different term, as it looks like what you are trying to do. The method must exist either within the page, or if it is in a control, then an identifier must exist for that control to determine which button was clicked, since it repeats the same control once on the page.
source to share
As Joel mentioned, you may have unintended behavior overlapping such writebacks. There is nothing wrong with that if you fully understand what is happening.
I think you really want to be WebMethod
. This will save your page, but will allow you to call a specific method on the server side:
public partial class _Default : Page
{
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
}
source to share