locked
Open email window C# asp.net datagrid as opposed to browser window RRS feed

  • Question

  • Would someone be so kind as to instruct me how to alter this code to open a new email client window as opposed to a new browser window?

            protected void lnkbtnWebsite_Click(object sender, EventArgs e)
            {
                var closeLink = (Control)sender;
                GridViewRow row = (GridViewRow)closeLink.NamingContainer;
                LinkButton lnk = (LinkButton)row.FindControl("lnkbtnWebsite");
                string mylnk = lnk.Text;
                string myhttp = "http://" + mylnk + "";
    
                if (!string.IsNullOrEmpty(mylnk))
                {
                    Page page = (Page)HttpContext.Current.Handler;
    
                    if (page == null)
                    {
                        throw new InvalidOperationException("Cannot redirect to new window outside Page context.");
                    }
                    string url = page.ResolveClientUrl(myhttp);
                    string script;
                    script = @"window.open(""{0}"", ""{1}"");";
                    script = String.Format(script, url, "", "");
                    ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
                }
            }
    Thank you in advance for the help!


    • Edited by Blue_Gem Wednesday, July 16, 2014 3:50 PM
    • Moved by Anne Jing Thursday, July 17, 2014 2:21 AM
    Wednesday, July 16, 2014 3:49 PM

Answers

  • Thank you for the reply Derik. I appreciate the post direction. I have been searching for the answer for this for days. Seems as if it should not be so complicated. Turns out the solution was quite simple

    <asp:BoundField DataField="Email" DataFormatString="<a href=mailto:{0}>{0}</a>" HeaderText="Email" HtmlEncodeFormatString="False" />
    http://forums.asp.net/t/1014242.aspx?How+to+create+mailto+in+gridview+



    • Edited by Blue_Gem Thursday, July 17, 2014 1:41 PM
    • Marked as answer by Blue_Gem Thursday, July 17, 2014 1:41 PM
    Thursday, July 17, 2014 1:39 PM

All replies

  • The syntax for launching a users default mail client is "mailto:user@domain.com" some clients will even support additional information like "mailto:user@domain.com?subject=Hello&body=Just saying hi!".

    This question would have been better asked in the ASP.Net forums though.


    "There's a way to do it better - find it." - Thomas Edison

    Wednesday, July 16, 2014 10:01 PM
  • Thank you for the reply Derik. I appreciate the post direction. I have been searching for the answer for this for days. Seems as if it should not be so complicated. Turns out the solution was quite simple

    <asp:BoundField DataField="Email" DataFormatString="<a href=mailto:{0}>{0}</a>" HeaderText="Email" HtmlEncodeFormatString="False" />
    http://forums.asp.net/t/1014242.aspx?How+to+create+mailto+in+gridview+



    • Edited by Blue_Gem Thursday, July 17, 2014 1:41 PM
    • Marked as answer by Blue_Gem Thursday, July 17, 2014 1:41 PM
    Thursday, July 17, 2014 1:39 PM