Friday, December 14, 2012

How to Print webpage ?

If you want to print same page then just write the javascript.


   function print() {
                window.print();
        }

if you want to print another webpage from the current page then write below scrpt



   function print(var str) {
               printWindow = window.open(  str,"mywindow");
               setTimeout('printWindow.print()', 3000);
               setTimeout('printWindow.close()', 3000);

        }

Tuesday, December 11, 2012

How to use HTTPS secure Page in URL in some Pages.


You may have to use https while Registration.

Please Add the Below code in Global.asax Page.

  protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var currentUrl = System.Web.HttpContext.Current.Request.Url;
            if (currentUrl.AbsoluteUri.Contains("Registration"))
            {
                if (!currentUrl.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.CurrentCultureIgnoreCase))
                {
                    //build the secure uri
                    var secureUrlBuilder = new UriBuilder(currentUrl);
                    secureUrlBuilder.Scheme = Uri.UriSchemeHttps;
                    //use the default port.
                    secureUrlBuilder.Port = string.IsNullOrEmpty(ConfigurationManager.AppSettings["HttpsPort"].ToString()) ? 443 : Convert.ToInt32(ConfigurationManager.AppSettings["HttpsPort"].ToString());
                    //redirect and end the response.
                    System.Web.HttpContext.Current.Response.Redirect(secureUrlBuilder.Uri.ToString());
                }
            }
        }

How to add JavaScript at runtime using C#

string Script=@”function ShowName() { var txt=document.getElementById(‘txtName’); alert(‘Your name is: ‘+txt.value); }”; 

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), “ShowName”, Script, true);