2009-10-29 50 views
1

我想使用弹出式窗口来更新2个字段,无论是手动输入还是从下拉列表中填充。 所以我需要一个提交按钮弹出。 我正在试验“我如何”视频中的代码。 在视频中,他们显示了一个从单选按钮列表中弹出的更新字段。 我决定改变它,以便不用关闭单选按钮SelectedIndexChanged事件中的弹出窗口,而是将其删除并将代码放在按钮提交事件中。 但是,我得到的消息; Microsoft JScript运行时错误:'this._postBackSettings.async'为空或不是对象 代码是;Ajax弹出式扩展程序 - 为什么它不适用于提交按钮


<%@ 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(); 

} 
+0

我不能让HTML到 – arame3333 2009-10-29 10:46:42

+0

你尝试过移动PopupControlExtender Panel1的外部问题呈现? – 2009-10-29 12:40:54

回答

2

我在这里找到答案; http://forums.asp.net/p/1038571/1440433.aspx

工作的答复是设置按钮属性; UseSubmitBehavior = false

为什么这个作品我不知道。谁会认为这将是解决方案?

+0

这是可行的,因为没有该属性,按钮将提交表单到服务器而不是执行必要的JavaScript。 – 2009-10-29 13:16:06

0

我看不出有任何异步回发在你的面板触发...可能是值得一试。

0

我已经有同样的问题,并没有真正找到任何令人满意的解决方案,直到我结束了http://siderite.blogspot.com/2009/02/thispostbacksettingsasync-is-null-or.html这正是我想要的。

只是为了避免在未来这里可能死链接的问题是代码:

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); 

在的情况下,一个提交而不_postBackSettings被设置创建它们,导致空引用异常消失_postBackSettings .async然后可用。

希望这有助于

G.

相关问题