我正在使用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();
答案 0 :(得分:2)
TargetControlID = "btnValidPopUp"
因为这个你的按钮回发是禁用的,所以它不会在点击事件上触发。要获得所需的结果集,使用按钮可以看到moddal popup的TragetControLiD为false,点击你的按钮btnValidPopUp写这个
mdlUserWorkShop.Show()