Issue is resolved now…
I have a simple web form where i need to save the email address and give user success or failure message accordingly in the Modal window and i want to do the validation and process from code behind and then show the Modal window.
Right now when i click on the subscribe button it quickly shows the modal window without executing the codebehind / server side code. Please find sample code below
<asp:ModalPopupExtender ID="ModalPopupExtender1" BackgroundCssClass="modalBackground" runat="server" PopupControlID="pnlMSG" CancelControlID="btnSubscribe"
TargetControlID="HiddenField1">
</asp:ModalPopupExtender>
Continue to Browse
<asp:Label ID="lblSubscriptionText" CssClass="lblfooterSubscribe"
runat="server" Text="Enter your email to subscribe to our Newsletter"
meta:resourcekey="lblSubscriptionTextResource1"></asp:Label>
<asp:TextBox ID="txtSubscribeEmail" runat="server" CssClass="txtSubEmail"
meta:resourcekey="txtSubscribeEmailResource1"></asp:TextBox>
<asp:Button ID="btnSubscribe" runat="server" Text="Subscribe"
CssClass="SubEmailBtn" ValidationGroup="SubEmail"
onclick="btnSubscribe_Click" meta:resourcekey="btnSubscribeResource1" />
<asp:HiddenField ID="HiddenField1" runat="server" />
protected void btnSubscribe_Click(object sender, EventArgs e)
{
//Regex reg = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
string email = txtSubscribeEmail.Text;
email = Helper.SafeSqlLiteral(email, 2);
string strSql = "INSERT INTO Subscribe (email, subscribeDate,Language)";
strSql += "VALUES ('" + email + "','" + DateTime.Now.ToString("yyyy/MM/dd") + "','" + Session["lang"].ToString() + "')";
int result = 0;
result = DataProvider.intConnect_Select(strSql);
lblSubEmailMSG.Visible = true;
btnSubscribe.Enabled = false;
//Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri);
// System.Threading.Thread.Sleep(2000);
this.ModalPopupExtender1.Show();
}
I tried to remove the TargetControlID=”btnSubscribe” property from the modalPopupExtender but it generates error saying TargetControlID cant be null or empty even removing the TargetControlID generates error.
If i use hidden field as TargetControl id then it executes the codebehin but it does the full post back and doesn’t show the modalwindow
Please suggest how can i hand this functionality..
What did i do? I resolved the issue by specifying TargeControl as Hidden Field and i was also using response.redirect which by mistake i had left uncommented. It works fine now
ISSUE RESOLVED
What did i do? I resolved the issue by specifying TargeControl as Hidden Field and i was also using response.redirect which by mistake i had left uncommented. It works fine now