allanmark
asked on
Parsing error from ASP.Net page when trying to execute javascript Alert
Greetings all
I am have a user control that sends an email. On successful send, I want to displaya message. I am using "Response.Write("<script>a lert('Your email has been sent.')</script>");" but this gives me an error - "PageRequestManagerParserE rrorExcept ion" (plse see attached jpg).
USerControl source and code-behind are attached.
What am I mising?
In advance, thanks!!
allanmark
I am have a user control that sends an email. On successful send, I want to displaya message. I am using "Response.Write("<script>a
USerControl source and code-behind are attached.
What am I mising?
In advance, thanks!!
allanmark
USER CONTROL SOURCE:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MimeEmailer.ascx.cs" Inherits="UserControls_MimeEmailer" %>
<script type ="text/javascript" language="javascript">
function ClearTheItXYZ()
{
document.getElementById('<%=txtSubject.ClientID %>').value = '';
document.getElementById('<%=txtMessage.ClientID %>').value = '';
var control = document.getElementById('<%=txtSubject.ClientID %>');
if( control != null ){ control.focus(); }
return false;
}
</script>
<ajaxext:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</ajaxext:ScriptManagerProxy>
<ajaxext:UpdatePanel ID="UpdatePanelA" runat="server">
<ContentTemplate>
<asp:Panel ID="pnlMail" runat="server" CssClass="pnlEMail" Width="600" BackColor="Lime">
<br />
<table id="email" style="position: relative" >
<!-- To -->
<tr>
<td style="width: 75px">
<asp:Label ID="lblTo" runat="server" CssClass="smallerFontSize">To:</asp:Label>
</td>
<td colspan="2">
<asp:DropDownList ID="ddlAddresses" runat="server" Width="325px"></asp:DropDownList>
</td>
</tr>
<tr>
<!-- Row: Blank -->
<td colspan="2" height="12"></td>
</tr>
<!-- Row: Subject -->
<tr>
<td style="width: 75px">
<asp:Label ID="lblSubject" runat="server" CssClass="smallerFontSize" AssociatedControlID="txtSubject" Width="175px" >Subject:</asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtSubject" runat="server" Width="350px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvSubject" runat="server" CssClass="smallFontSize" ControlToValidate="txtSubject"
ErrorMessage="Required Field" SetFocusOnError="True" Style="position: relative" ValidationGroup="SendEmail"></asp:RequiredFieldValidator></td>
<!-- End: Row: Subject -->
</tr>
<tr>
<!-- Row: Blank -->
<td colspan="2" height="12"></td>
</tr>
<tr>
<!-- Row: Message -->
<td style="width: 75px">
<asp:Label ID="lblMessage" runat="server" CssClass="smallerFontSize" AssociatedControlID="txtMessage">Message:</asp:Label>
</td>
<td colspan="2">
<asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Width="475px" Height="200px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvMessage" runat="server" CssClass="smallFontSize" ControlToValidate="txtMessage"
ErrorMessage="Required Field" SetFocusOnError="True" Style="position: relative" ValidationGroup="SendEmail"></asp:RequiredFieldValidator>
</td>
<!-- End: Row: Message -->
</tr>
<tr>
<!-- Row: Blank -->
<td colspan="2" height="1"></td>
</tr>
<!-- End: table id="email". -->
</table>
<center>
<asp:Button ID="btnSendTheEMail" runat="server" Text="Send" ValidationGroup="SendEmail" CssClass="buttons" OnClick="btnSendTheEMail_Click" />
<asp:Button ID="btnClear" runat="server" Text="Clear" OnClientClick="return ClearTheItXYZ()" CausesValidation="False" />
</center><br />
</asp:Panel>
<!-- <asp:Panel ID=pnlMail"> -->
</ContentTemplate>
</ajaxext:UpdatePanel>
USER CONTROL CODE BEHIND:
using System;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataTransferObjects;
using BusinessLogic;
public partial class UserControls_MimeEmailer : System.Web.UI.UserControl
{
private List<EMailAddress> emailList = new List<EMailAddress>();
protected void Page_Load(object sender, EventArgs e)
{
// Load the Page-specific stylesheet.
//HtmlLink lnk = (HtmlLink)Master.FindControl("cssLink");
HtmlLink lnk = new HtmlLink();
lnk.Href = "~/CSS/UserControls.css";
// txtMessage.Attributes.Add("OnClientClick", "return false;");
if (!Page.IsPostBack)
{
emailList = BusinessLogic.Business.GetEmailAddress();
ddlAddresses.DataSource = emailList;
ddlAddresses.DataTextField = "Name";
ddlAddresses.DataValueField = "Email";
ddlAddresses.DataBind();
ddlAddresses.SelectedIndex = 0;
Session["selectedEmail"] = ddlAddresses.SelectedIndex;
}
else
{
if (Session["selectedEmail"] != null)
{
ddlAddresses.SelectedIndex = (int)Session["selectedEmail"];
}
else
{
ddlAddresses.SelectedIndex = 0;
Session["selectedEmail"] = ddlAddresses.SelectedIndex;
}
}
}
protected void btnSendTheEMail_Click(object sender, EventArgs e)
{
bool isEmailSent = BusinessLogic.Business.SendEmail(ddlAddresses.SelectedValue.ToString(),
System.Configuration.ConfigurationManager.AppSettings["AdminEmail"].ToString(),
txtSubject.Text,
txtMessage.Text + Environment.NewLine + Environment.NewLine);
if (isEmailSent)
{
Response.Write("<script>alert('Your email has been sent.')</script>");
ClearTheFields();
}
else
{
// Message to go here.
}
}
private void ClearTheFields()
{
ddlAddresses.SelectedIndex = 0;
txtSubject.Text = "";
txtMessage.Text = "";
txtSubject.Focus();
}
}
Error.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bummer!
The UserControl is on a panel that is the TargetControl for an AJAX ModalPopup. If the "Send" button is outside the UpdatPanel then it causes the popup to close!
The UserControl is on a panel that is the TargetControl for an AJAX ModalPopup. If the "Send" button is outside the UpdatPanel then it causes the popup to close!
Sorry. I didn't know it is Modalpopup. It is always better to use RegisterStartupScript rathen than Response.write method when you want to execute javascript command after the button postback event. Replace Response.Write with the following code. I hope this help.
ClientScript.RegisterStart upScript(t ypeof(Stri ng), "", "<script>alert('Your email has been sent.')</script>");
ClientScript.RegisterStart
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks!!!
ASKER
So anything with a Resonse.write in it is not going to work! I need to inform the user in some way (was hoping to do so via a message popped up) - is there a way to do this?