Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Parsing error from ASP.Net page when trying to execute javascript Alert

Posted on 2009-04-07
7
Medium Priority
?
468 Views
Last Modified: 2013-12-17
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>alert('Your email has been sent.')</script>");" but this gives me an error - "PageRequestManagerParserErrorException" (plse see attached jpg).

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" />  
    &nbsp;&nbsp;&nbsp;
    <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();
    }
 
 
}

Open in new window

Error.jpg
0
Comment
Question by:allanmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
AlvinLim84 earned 700 total points
ID: 24084706
0
 

Author Comment

by:allanmark
ID: 24084809
Good articles!!

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?

0
 
LVL 2

Assisted Solution

by:AlvinLim84
AlvinLim84 earned 700 total points
ID: 24084896
Not really must remove the response.write(). You can try to move the button name 'btnSendTheEMail' outside of the Panel such as the following part in aspx page. It should be working as expected and popped up the message to user.
<!-- End: table id="email". -->
    </table>     
 
    </asp:Panel>
    <!-- <asp:Panel ID=pnlMail"> -->
 
</ContentTemplate>        
</ajaxext:UpdatePanel>
 
<center>
    <asp:Button ID="btnSendTheEMail" runat="server"  Text="Send" ValidationGroup="SendEmail" CssClass="buttons" OnClick="btnSendTheEMail_Click" />  
    &nbsp;&nbsp;&nbsp;
    <asp:Button ID="btnClear" runat="server" Text="Clear" OnClientClick="return ClearTheItXYZ()" CausesValidation="False" />        
    </center><br />

Open in new window

0
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 

Author Comment

by:allanmark
ID: 24085174
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!
0
 
LVL 2

Expert Comment

by:AlvinLim84
ID: 24085590
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.RegisterStartupScript(typeof(String), "", "<script>alert('Your email has been sent.')</script>");
0
 
LVL 14

Assisted Solution

by:GiftsonDJohn
GiftsonDJohn earned 300 total points
ID: 24085601
Use as follows.

ScriptManager.RegisterClientScriptBlock(btnSendTheEMail, btnSendTheEMail.GetType(), "mailsent", "alert('Your email has been sent.')", true);
0
 

Author Closing Comment

by:allanmark
ID: 31567386
Many thanks!!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question