Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2007, 11:40 PM
Registered User
 
Join Date: Mar 2007
Location: New Port Richey, FL, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Redirect to Email

I have a button click event that redirects to mailto: and then a group of email addresses. When I click the button, my email program launches with the email addresses loaded like it should, however, the browser loads a blank page with mailto: in the address bar. Is there a way to do this with out opening the blank page? Below is the code that I'm using.

private void Button1_Click(object sender, System.EventArgs e)
{
    Response.Redirect("mailto:" + Session["GroupEmail"]);
}

private void LoadGroupEmail(string s)
{
   // check s for the team name then laod all the data
   OleDbConnection myConn = new OleDbConnection(Session["ConnStr"].ToString());
myConn.Open();

   // add the query
   string sql = "Select * from TeamRoster where Team = '" + s + "' and Name = 'Group Email'";

   // create the command object
   OleDbCommand myCommand = new OleDbCommand(sql,myConn);

   // create an object to handle the return
   OleDbDataReader Result = myCommand.ExecuteReader();

   if (Result.HasRows)
   {
      if (Result.Read())
      {
         Session["GroupEmail"] = Result["Email"].ToString();
      }
   }
   myConn.Close();
}




  #2 (permalink)  
Old March 12th, 2007, 05:25 PM
Friend of Wrox
 
Join Date: Jun 2004
Location: Chennai, Tamil Nadu, India.
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Can you try this?

Code:
private void Button1_Click(object sender, System.EventArgs e)
{
    Response.Redirect("mailto:" + Session["GroupEmail"]).ToString();
}
Regards
Ganesh
http://ganeshprof.blogspot.com
  #3 (permalink)  
Old March 12th, 2007, 10:00 PM
Registered User
 
Join Date: Mar 2007
Location: New Port Richey, FL, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That causes a blank page to load. I wanted a way to do it without leaving the page. I eventally exclueded the bulk email address from the query. Then created anouther procedure that only queries the group address and added it to the url of a link button. Now it works without leaving the page.

Thanks for your response though, I wasn't sure if there was any on here except people looking for help.

Jim

  #4 (permalink)  
Old March 13th, 2007, 01:45 AM
Friend of Wrox
 
Join Date: Jun 2004
Location: Chennai, Tamil Nadu, India.
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

can you check what the Session["GroupEmail"] contains at this point? You can do some debugging stuff for this.

Code:
private void Button1_Click(object sender, System.EventArgs e)
{
    Response.Redirect("mailto:" + Session["GroupEmail"].ToString());
}
Regards
Ganesh
http://ganeshprof.blogspot.com
Find your solution here...
  #5 (permalink)  
Old March 13th, 2007, 07:14 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In your current implementation, you will never get the browser to NOT direct to a blank page. By using Response.Redirect you are telling the browser to goto a new page albeit you are providing a special command to spawn your email application. Simply put, your browser is ALWAYS going to go to mailto:... using this method.

Why not build a javascript string that will spawn your email client and write that back to the client? That will not cause your browser to move to a different page.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #6 (permalink)  
Old March 13th, 2007, 05:14 PM
Registered User
 
Join Date: Mar 2007
Location: New Port Richey, FL, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I stated in the original question, I was looking for a more elegant solution to the problem then what I eventually came up with. I didn't want to write any more code and I didn't want to hit the database again. I was looking for a way to fill the data reader and extract the group email from it while still filling the data grid. As it turns out, that's really not the most elegant way to do it. The Response.Redirect as every one has stated will always redirect to an empty page. My second post on this subject is the one with the solution that I came up with. I think that it's the best and it works. Here is the code that I used. As you will see, I eliminated the button all together.

private void LoadGroupEmail(string s)
        {
            // check s for the team name then laod all the data
            OleDbConnection myConn = new OleDbConnection(Session["ConnStr"].ToString());
            myConn.Open();

            // add the query
            string sql = "Select * from TeamRoster where Team = '" + s + "' and Name = 'Group Email'";

            // create the command object
            OleDbCommand myCommand = new OleDbCommand(sql,myConn);

            // create an object to handle the return
            OleDbDataReader Result = myCommand.ExecuteReader();

            if (Result.HasRows)
            {
                if (Result.Read())
                {
                    Session["GroupEmail"] = Result["Email"].ToString();
                }
            }
            myConn.Close();
            hlGroupEmail.Text = s + " Group Email";
            hlGroupEmail.NavigateUrl = "mailto:" + Session["GroupEmail"];
        }

        private void LoadData(string s)
        {
            // check s for the team name then laod all the data
            OleDbConnection myConn = new OleDbConnection(Session["ConnStr"].ToString());
            myConn.Open();

            // add the query
            string sql = "Select * from TeamRoster where Team = '" + s + "' and Name <> 'Group Email'";

            // create the command object
            OleDbCommand myCommand = new OleDbCommand(sql,myConn);

            // create an object to handle the return
            OleDbDataReader Result = myCommand.ExecuteReader();

            DataGrid1.DataSource = Result;
            DataGrid1.Width = 600;
            DataGrid1.DataBind();
            myConn.Close();
        }
        #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.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
            this.LinkButton3.Click += new System.EventHandler(this.LinkButton3_Click);
            this.LinkButton4.Click += new System.EventHandler(this.LinkButton4_Click);
            this.btnWings.Click += new System.EventHandler(this.btnWings_Click);
            this.btnAlt.Click += new System.EventHandler(this.btnAlt_Click);
            this.btnRefs.Click += new System.EventHandler(this.btnRefs_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void LinkButton2_Click(object sender, System.EventArgs e)
        {
            // laod data for BOA
            DataGrid1.BorderColor = System.Drawing.Color.RoyalBlue;
            LoadData("Black Bears");
            LoadGroupEmail("Black Bears");
        }

You can view this in action by going to http://www.ebhl.org
and clicking on the Rosters button at the top.

Thanks again

Jim

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect SKhna ASP.NET 2.0 Basics 1 February 9th, 2008 08:14 AM
Automatic Redirect tna55 ASP.NET 2.0 Basics 2 April 4th, 2007 07:32 AM
Redirect Problems faithfulman ASP.NET 2.0 Basics 11 September 17th, 2006 04:56 AM
header redirect dazednconfused Beginning PHP 5 September 9th, 2003 01:25 PM



All times are GMT -4. The time now is 02:36 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.