I am using AJAX modal popup extender as a sub form. I have a page with text boxes, when a user click a button the data from text boxes should be added to the database and popup appear. The problem is that when the button is clicked, pop up appears but nothing is added to database. If i comment the pop up, everything works fine. Please help. Thanx
<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>
Code behind:
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();