我使用 AJAX 模态弹出扩展器作为子表单。我有一个带有文本框的页面,当用户单击按钮时,应将文本框中的数据添加到数据库并出现弹出窗口。问题是,当单击按钮时,会出现弹出窗口,但没有任何内容添加到数据库中。如果我评论弹出窗口,一切正常。请帮忙。谢谢
<asp:Button ID="btnNewSubmt" runat="server" Text="Submit"
ValidationGroup = "NewUser" onclick="btnNewSubmt_Click" OnClientClick = "return isPageValid()"/>
<asp:Button ID="btnValidPopUp" runat="server" Text="Button" style = "display:none"/>
<asp:Panel ID="pnlUserWorkShop" runat="server">
<asp:SqlDataSource ID="sqlWorkSName" runat="server"
ConnectionString="<%$ ConnectionStrings:WildLife_EducationConnectionString %>"
SelectCommand="SELECT DISTINCT [WorkshopName] FROM [tblWorkshop]"></asp:SqlDataSource>
<asp:Label runat="server" Text="Please select work shop you would like to register for:"></asp:Label>
<asp:DropDownList ID="ddlWorkShopChose" runat="server"
DataSourceID="sqlWorkSName" AppendDataBoundItems="True"
DataTextField="WorkshopName" DataValueField="WorkshopName">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<asp:ModalPopupExtender ID="mdlUserWorkShop" runat="server" TargetControlID = "btnValidPopUp" PopupControlID = "pnlUserWorkShop" BehaviorID = "myModalPopup" >
</asp:ModalPopupExtender>
后面的代码:
using (SqlConnection conn = new SqlConnection(@"Data Source=MyDataBase;Initial Catalog=MyDataBase;Integrated Security=True;"))
SqlCommand CmdSql = new SqlCommand
("INSERT INTO [tbluser] ([UserLastName], [UserFirstName], [UserMiddleInitial]) VALUES (@UserFirstName,@UserLastName, @UserFirstName, @UserMiddleInitial)", conn);
conn.Open();
CmdSql.Parameters.AddWithValue("@UserLastName", txtNewUserLN.Text.ToString());
CmdSql.Parameters.AddWithValue("@UserFirstName", txtNewUserFN.Text.ToString());
CmdSql.Parameters.AddWithValue("@UserMiddleInitial", txtNewUserMI.Text.ToString());
CmdSql.Connection = conn;
CmdSql.ExecuteNonQuery();
conn.Close();