开发者

Ajax popup extender - why will it NOT work with a submit button

I want to use a popup where I want to update 2 fields, either manually entered or populated from a drop dow list. So I need a popup with a submit button. I am experimenting with the code from the "How do I" videos. In the video they show a field being updated from a popup with a radiobutton list. I decided to change it so that instead of closing the popup in the radiobutton SelectedIndexChanged event, I removed that and put the code in a button submit event. However I get the message; Microsoft JScript runtime error: 'this._postBackSettings.async' is null or not an object The code is;


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        function UpdateField(text)
        {
            var test = text + ' - SEND A MEETING REQUEST!';
            $get("MyTextBox").value = test;
//            $get("lblTest").value = test;
//            
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <asp:UpdatePanel runat="server" ID="updTest">
                <ContentTemplate>
            <br />
            ToDo:
            <asp:TextBox ID="MyTextBox" runat="server" Width="538px"></asp:TextBox>
            <br />
            <asp:Panel ID="Panel1" runat="server" CssClass="popupControl" DefaultButton="btnTest">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:RadioButtonList ID="RadioButtonList1" runat="server"                             Width="146px">
                            <asp:ListItem Text="Scott Guthrie"></asp:ListItem>
                            <asp:ListItem Text="Simon Muzio"></asp:ListItem>
                            <asp:ListItem Text="Brian Goldfarb"></asp:ListItem>
                            <asp:ListItem Text="Joe Stagner"></asp:ListItem>
                            <asp:ListItem Text="Shawn Nandi"></asp:ListItem>
                        </asp:RadioButtonList>
                        <div style="padding:10px;">
                            <asp:Button runat="server" ID="btnTest" Text="Submit" onclick="btnTest_Click"  />
                        </div>
                    </ContentTemplate>
                </asp:UpdatePanel>
            <br />
            <ajaxToolkit:PopupControlExtender ID="PopupControlExtender1" runat="server" 开发者_运维知识库CommitProperty="value"
                CommitScript="UpdateField(e.value);" PopupControlID="Panel1"
                Position="Bottom" TargetControlID="MyTextBox">
            </ajaxToolkit:PopupControlExtender>   
            </asp:Panel> 
            <div style="padding:20px;"><asp:Label runat="server" ID="lblTest" Text="Test"/>         </div>
                            </ContentTemplate>
            </asp:UpdatePanel>

        </div>
    </form>    
</body>
</html>



protected void btnTest_Click(object sender, EventArgs e)
{
    lblTest.Text = RadioButtonList1.SelectedItem.Text + " hello";
    PopupControlExtender.GetProxyForCurrentPopup(this.Page).Commit(RadioButtonList1.SelectedValue);
    // Reset the selected item
    RadioButtonList1.ClearSelection();

}


I found the answer here; http://forums.asp.net/p/1038571/1440433.aspx

The reply that worked was to set the button property; UseSubmitBehavior=false

Why this works I do not know. Who would have thought this would be the solution?


I don't see any ASYNC POSTBACK triggers in your panel... Might be worth a look.


I've had the same problem and haven't really found any satisfying solution until I ended up on https://siderite.dev/blog/thispostbacksettingsasync-is-null-or.html which does exactly what I want.

Just to avoid problems with possible dead links in the future here is the code:

var script = @"
if (Sys &&
    Sys.WebForms && Sys.WebForms.PageRequestManager &&
    Sys.WebForms.PageRequestManager.getInstance) 
{
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm &&
       !prm._postBackSettings)
    {
        prm._postBackSettings = prm._createPostBackSettings(false, null, null);
    }";

ScriptManager.RegisterOnSubmitStatement(
    Page, 
    Page.GetType(), 
    "FixPopupFormSubmit", 
    script);

In case of a submit without the _postBackSettings being set it creates them, causing the null reference exception to disappear as _postBackSettings.async is then available.

Hope this helps,

G.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜