Response Use MailTo

  • Thread starter Thread starter Matt F
  • Start date Start date
M

Matt F

First off, my experience is primarily with windows apps, so I appologize for
the simplicity of this.

This is using v1.1 of the framework:

I've added a button to a aspx page that generates a new email - contents,
who it's going to etc. info generated in code.

The entire value of the link is in a string called MailString

I've confirmed the email is opened on the client machine etc. via
Response.Redirect(MailString);

The problem is this is obviously not quite what I want -- this clears the
page in the browser. I want to leave the user on the page and just open the
new mail message.

Any suggestions?
 
Matt said:
First off, my experience is primarily with windows apps, so I appologize for
the simplicity of this.

This is using v1.1 of the framework:

I've added a button to a aspx page that generates a new email - contents,
who it's going to etc. info generated in code.

The entire value of the link is in a string called MailString

I've confirmed the email is opened on the client machine etc. via
Response.Redirect(MailString);

The problem is this is obviously not quite what I want -- this clears the
page in the browser. I want to leave the user on the page and just open the
new mail message.

Any suggestions?

Open it in a new window.
 
Hi Matt,

Based on your actual requirement, there might be several approaches:

1) If you need to do this in a postback after processing, then you can use
following code:

ClientScript.RegisterStartupScript(GetType(), "mailTo",
"window.open('the_link.aspx?param=foo', '_blank')", true);

This will make the javascript window.open to open a new window to the
target url.

2) If you're using Hyperlink controls, then you can change its Target
property to '_blank' and at runtime you determine its NavigateUrl: when
it's clicked, there's no postback, instead client browser will open the url
in a new window.


Please let me know your actual requirement so that I can elaborate more.
Thanks.



Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Sorry for the delay in getting back to this. I beleive it's the first
option that you've listed below that I'm looking for. Could you elaborate a
bit?
 
Hi Matt,

Please see following test code (which is a complete webform):


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("mailto:test");
}

protected void LinkButton2_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(GetType(), "mailto",
"window.open('mailto:test', '_blank')", true);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="LinkButton1" runat="server"
OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server"
OnClick="LinkButton2_Click">LinkButton</asp:LinkButton></div>
</form>
</body>
</html>


The first LinkButton's Click is using the approach as you described in your
question, which will clear the response after opening the new mail window.

The second LinkButton's Click will register a client-side startup
javascript which will open the url ('mailto' in this case) in a new blank
window, the response will not be cleared.


Hope this is the correct understanding of your question.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Walter,

Thank you for your response. As mentioned in my original post, this is for
use with V1.1 of the framework and the ClientScript class doesn't exist.

Other suggestions?
 
Hi Matt,

I'm sorry that I overlooked your runtime version.

For .NET 1.1, we can use Page.RegisterStartupScript. I created a complete
1.1 WebForm for testing:

WebForm1.aspx:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication4.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:LinkButton id="LinkButton1" style="Z-INDEX: 101; LEFT: 64px;
POSITION: absolute; TOP: 40px"
runat="server">LinkButton</asp:LinkButton>
</form>
</body>
</HTML>


WebForm1.aspx.cs:


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication4
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton LinkButton1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.LinkButton1.Click += new
System.EventHandler(this.LinkButton1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void LinkButton1_Click(object sender, System.EventArgs e)
{
Page.RegisterStartupScript("mailto", "<script>window.open('mailto:test',
'_blank')</script>");
}
}
}


Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Walter,

Thanks so much for your help with this. That handles just what I need very
nicely.

I'm beginning to think that my studies into asp.net should probably also
include a sprinkling of Java.
 
Walter,

In using this initially it appears to work, however I've hit a limitation of
the implementation in testing. In my mailto string I include the email
address, subject line and body of the email.

The problem I'm running into is for some reason the body portion is only
passing the first 100 characters. I need around double that.
 
Found the problem here --- not a size limitation, but rather a rookie
mistake. A part of the body that I am populating includes and & character
in a url. Once I swapped out the & for the hex value of /26 all works fine.
 
Hi Matt,

I'm glad the issue is not solved.

Thank you for using MSDN Managed Newsgroup support service!


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top