I have an asp.net 4.0 app where all pages use a master page. I have several dynamic aspects going on in both the masterpage and the child of the pages. For both I'd like to be able to use the built in Microsoft ScriptManager with this kind of pattern:
Code behind:
using System;
using System.Web;
using System.Web.Services;
namespace MyApp.Secure
{
public partial class myPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string GetString()
{
return "abc";
}
}
}
Then in the page content itself:
<script>
PageMethods.GetString(OnSucceeded, OnFailed);
function OnSucceeded(rslt) {
alert('cool,worked.');
}
function OnFailed(error) {
alert('ooops,failed.');
}
</script>
So, to use this technique I'd like to expose static [WebMethod]'s in both my masterpage and my child page. My question is, how do I manage this with a ScriptManager? From my understanding, I need to have a ScriptManager within a form tag (why?) so that a javascript library is added to allow me to use the PageMethods object. Should I just create one ScriptManager in my masterpage and tuck it in a useless form tag in the masterpage? Will that ScriptManager pickup the [WebMethod] functions in my child page? And what about that form tag: I know I can only have one form runat='server' tag so how would I manage a that with other forms I need within my masterpage? Like my little form that wraps my search function at the top of the page?
Thanks