ClientScript from a web form with ScriptManager on a master page

Last post 02-28-2007 10:51 PM by anishdevasia. 1 replies.

Sort Posts:

  • ClientScript from a web form with ScriptManager on a master page

    02-28-2007, 11:13 AM

    I have a master page, on the master page I have added the asp:ScriptManager.

    On a webform that uses the master page above I want to validate som fields on the server side during a ajax postback.

    Question: How do I output an alert box on the server side displayed on the client?

    I tried use the AsyncPostBackError event, but it is no accessible from the web form page (not even if I try to add a handler using DirectCast(Me.Master.FindControl("ctlScriptManager"), ScriptManager)), and is not a member of the asp:ScriptManagerProxy.

    Anyone have a solution for this? Is there a better way than using the AsyncPostBackError?

    Best regards,

    Fredrik

  • Re: ClientScript from a web form with ScriptManager on a master page

    02-28-2007, 10:51 PM

    You can thorw a custom exception from your validator function. Then modify the AsyncPostbackErrorMessage accordingly in master page as given below(master page code)

    <script runat="server">

    protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)

    {

    ScriptManager1.AsyncPostBackErrorMessage = e.Exception.Message;

    }

    </

    script>

    <

    html xmlns="http://www.w3.org/1999/xhtml" >

    <

    head runat="server">

    <title>Untitled Page</title>

    </

    head>

    <

    body>

    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server"

    OnAsyncPostBackError="ScriptManager1_AsyncPostBackError">

    </asp:ScriptManager>

    <div>

    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

    </asp:contentplaceholder>

    </div>

    </form>

    </

    body>

    </

    html>
    Anish Devasia
    MCP,MCAD
    ---------------------------------------------------








Page 1 of 1 (2 items)
Microsoft Communities
Page view counter