Tuesday, March 28, 2017

URL Rewrite - Config entries to Hide .html extension

Recently we came across a requirement to hide .html extension in URL and following URL rewrite configuration entry to web.config provide the solution to hide the .html extension.


Monday, February 9, 2009

JQuery event is not working after updatepanel update

After each AJAX Asynchronous method call we have to register the script block. This can be done using the below statements.

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    
function EndRequestHandler()
{
//JQuery event registration of your script code
}

Thursday, January 15, 2009

Loading external javascript files in web page

External java script files will be included into web page by using <script> tag. 

Here is the example of including external java script file in web page. 

<script src="Cmmon.js" type="text/javascript"></script> 

Script tag should be closed properly. The following example is wrong way of including external java script files. 

<script src="Cmmon.js" type="text/javascript" />

With the above statement only one javascript file will be loaded into page, when you try to load multiple java script files.

this._form is null javascript error

Here is one scenario which I had faced in my application for this issue. 

I had included some of the external java script files in my application with below syntax. 

<script src="Common.js" type="text/javascript" /> Wrong 

It is wrong the script tag should be closed with “</script>” instead of "/>". Then only all the scripts will be loaded into the page properly. 

<script src="Common.js" type="text/javascript"></script> Correct

Sunday, January 4, 2009

SQL Statement for getting the list of tables which has identity columns

SQL statements to get the list of tables which has IDENTITY columns.

Statement 1:
-------------
SELECT 
     QUOTENAME(SCHEMA_NAME(t.schema_id)) + '.' + QUOTENAME(t.name) AS TableName 
FROM sys.columns AS c  
    INNER JOIN 
    sys.tables AS t  
    ON t.[object_id] = c.[object_id] 
WHERE c.is_identity = 1

Results
--------
[dbo].[Table1]
[dbo].[Table2]
[dbo].[Table3]

Statement 2:
-------------
SELECT T.NAME AS TableName FROM sys.columns AS c
    INNER JOIN sys.tables AS t
ON t.[object_id] = c.[object_id] WHERE c.is_identity = 1

Results
--------
Table1
Table2
Table3

Wednesday, December 17, 2008

Specifying static port number for web application

Here are the steps to specify static port number to web application.
1) Right click on project name and select properties.
2) In the properties window select web tab from the left tabs.
3) In project web properties select “Specific port” option which is under servers and specify the port number.

Thursday, December 11, 2008

Using HttpWebRequest & HttpWebResponse in XML Web Services

Calling a web method using HttpWebRequest and HttpWebResponse.
Service1.asmx.cs
---------------------
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
namespace WebService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public int Add(int a, int b)
{
return a + b;
}
}
}
Class1.cs
---------

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Net;
using System.IO;
namespace WebService1
{
public class Class1
{
public string GetResponse(string InputXML, string WebserviceURL, string strSoapAction)
{
string postData = InputXML;
UTF8Encoding encoding = new UTF8Encoding();
byte[] postBytes = encoding.GetBytes(postData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(WebserviceURL);
req.Method = "POST";
req.ContentType = "text/xml; charset=utf-8";
req.Headers.Add("SOAPAction", strSoapAction);
req.ContentLength = postBytes.Length;
Stream postStreem = req.GetRequestStream();
postStreem.Write(postBytes, 0, postBytes.Length);
postStreem.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(res.GetResponseStream());
return reader.ReadToEnd();
}
}
}

Method call:
-------------

Class1 obj = new Class1();
string str = obj.GetResponse(TextBox1.Text, "http://localhost:62202/Service1.asmx", "http://tempuri.org/Add");
Response.Write("Response from Webservice:
Sum of two numbers: " + str);