title: How can i use response.redirect from inside a function defined in Class file in c# 3.0
body: <p>I have a simple function <code>GetPageName(String PageFileName, String LangCode)</code> defined inside a class file. I call this function from <code>default.aspx.cs</code> file, In this function I am not able to use <code>Response.Redirect("Error.aspx")</code> to show user that error has been generated.</p>
  
  <p>Below is example of Code</p>
  
  <pre><code>public static string GetPageName(String PageFileName, String LangCode)
  {
       String sLangCode = Request("Language");
       String pgName = null;
       if ( sLangCode.Length &gt; 6)
       {
          Reponse.Redirect("Error.aspx?msg=Invalid Input");
       }
       else
       {
           try
           {            
               String strSql = "SELECT* FROM Table";
  
               Dataset ds = Dataprovider.Connect_SQL(strSql);
  
           }
           catch( Exception ex)
           {
              response.redirect("Error.aspx?msg="+ex.Message);
           }
       }
       return pgName;
  }
  </code></pre>
  
  <p>I have may function defined in Business and Datalayer where i want to trap the error and redirect user to the Error page.</p>