Posts

Showing posts from April, 2008

How to hide generated javascript file in visual studio code

In this post I am going to show you a cool trick in visual studio code. Let's suppose you are writing typescript code in visual studio code and you want to hide generated javascript code.

Create .vscode folder in your folder and then create settings.json file and paste following code

{ "files.exclude": { "node_modules":true, "**/.git": true, "**/.DS_Store": true, "**/*.js.map": true, "**/*.js": {"when": "$(basename).ts"}     } }

How To display a JavaScript alert window during a partial postback, from code behind

Image
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxError.aspx.cs"
Inherits="AjaxError" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ScriptManagerID="ScriptManger1"runat="server">
</asp:ScriptManager>
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:ButtonID="btnRedirect"runat="server"Text="Redirect"
OnClick="btnRedirect_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>




using System;
using System.Data;
using System.Configuration…

How to detect browser closing and navigating to some other page

<!DOCTYPEHTMLPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><scripttype="text/jscript">var leaving=true; window.onbeforeunload = function(e) { if (!e) e = event; if (leaving) e.returnValue = "You might loose your changes"; } </script><title></title></head><body><ahref="http://www.google.com/">Leave</a><ahref="page1.htm"onClick="leaving=false">stay on site</a></body></html>

Using a Class Factory to Create Objects— Single Factory

Image
using System;
using System.Collections.Generic;
using System.Text;

namespace SampleFactoryClass
{
publicinterface IApparel // Interface representing product
{

string ShowMe();

bool Knit // Property to indicate if Knit

{ get; }

}

publicclass SportsShirt : IApparel
{

publicstring ShowMe()
{

return ("Sports Shirt");

}

publicbool Knit

{ get { returntrue; } }

}

publicclass DressShirt : IApparel
{

publicstring ShowMe()
{

return ("Dress Shirt");

}

publicbool Knit

{ get { returnfalse; } }

}

// Factory to return instances of apparel classes

publicclass ApparelFactory
{

public IApparel CreateApparel(string apptype)
{

switch (apptype)
{

case"MDRSHIRT":

returnnew DressShirt();

case"MSPSHIRT":

returnnew SportsShirt();

}

returnnull;

}
publicstaticvoid Main()
{

ApparelFactory factory = new ApparelFactory();

IApparel ob1 = factory.CreateApparel("MDRSHIRT"…

How To Insert A New Row In GridView

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InsertRowInGridView.aspx.cs" Inherits="InsertRowGridView" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headid="Head1"runat="server"><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:GridViewAutoGenerateColumns="False"ID="GridView1"runat="server"OnRowCancelingEdit="GridView1_RowCancelingEdit"OnRowEditing="GridView1_RowEditing"OnRowUpdating="GridView1_RowUpdating"OnRowCommand="GridView1_RowCommand"><Columns><asp:TemplateFieldShowHeader="False"><EditItemTemplate><asp:LinkButtonID="LinkButton1"runat=&qu…

how to access and invoke private methods,fields or properties

using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace ReflectionTe { /// <summary>/// Holds blog information/// </summary>publicclass Blog { /// <summary>/// Gets the posts count./// </summary>privatestaticint PostsCount { get { return 10000; } } /// <summary>/// Gets the description./// </summary>/// <returns></returns>privatestring GetDescription() { return@"A weblog dedicated to obsessively profiling reviewing new Internet products and companies"; } /// <summary>/// Changes the name of the blog./// </summary>/// <param name="newName">The new name.</param>privatestring ChangeBlogName(string newName) { name = newName; return name; } string url = "http://techcrunc…

Cancelling an Asynchronous Request

Image
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxCancel.aspx.cs"
Inherits="AjaxCancel" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="S1"runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">
<ContentTemplate>
<%= System.DateTime.Now.ToLongTimeString() %>
<asp:ButtonID="btnRefresh"runat="server"Text="Update"
OnClick="btnRefresh_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>

<scriptt…

How to Raise Events for FILEUPLOAD Control

Image
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EventFileUpload.aspx.cs" Inherits="EventFileUpload" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><scripttype="text/javascript">function GetFileName(val) { var i = val.lastIndexOf("\\"); return val.substring(i+1); } </script><title>Untitled Page</title></head><body><formid="form1"runat="server"><div><asp:FileUploadID="FileUpload1"runat="server"size="40"onchange="this.form.TextBox1.value=GetFileName(this.value);"/><asp:TextBoxID="TextBox1"runat="server"/></div></form></body></html>

How To Create Templated Databound Controls

Image
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DivView.aspx.cs"
Inherits="DivView" %>

<%@ Register Namespace="BoundCustomControl" TagPrefix="custom"
Assembly="DataBoundControl" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
<styletype="text/css">
.movies
{
width:500px;
}
.movies div
{
border:solid 1px black;
padding:10px;
margin:10px;
}
</style>
</head>
<body>
<formid="form1"runat="server">
<div>
<custom:DivViewID="a"runat="server"CssClass="movies">
<ItemTemplate>
<h1>
<%# Eval("Title") %>
</h1&…

How To Add Dynamic AJAX Control Toolkit - Calendar Extender

Image
<%@ Page Language="C#" AutoEventWireup="true"

CodeFile="DynamicAjaxExtender.aspx.cs"
Inherits="DynamicAjaxExtender" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<asp:ScriptManagerID="ScriptManger1"
runat="server"></asp:ScriptManager>
<div>
<asp:PlaceHolderID="placeHolder1"
runat="server"></asp:PlaceHolder>
<asp:ButtonID="Button1"runat="server"
OnClick="Button1_Click"Text="Create"/></div>
</form>
</body>
</html>


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using Syst…

How To Add Column Summery In GridView

Image
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DisplayColumnSummery.aspx.cs"
Inherits="DisplayColumnSummery" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="grdMovies"OnRowDataBound="grdMovies_RowDataBound"AutoGenerateColumns="false"
ShowFooter="true"runat="server">
<Columns>
<asp:BoundFieldDataField="Name"HeaderText="Name"/>
<asp:TemplateFieldHeaderText="Box Office Totals">
<ItemTemplate>
<%# Eval("SellPrice", "{0:c}")%>
</ItemTemplate>
<FooterTemplate>
<a…

How To Add Default Button(For IE and Mozila)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultButton.aspx.cs" Inherits="DefaultButton" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headid="Head1"runat="server"><title>Untitled Page</title><scripttype="text/javascript">function press(evt) { if(evt.which || evt.keyCode) { if ((evt.which == 13) || (evt.keyCode == 13)) { var buttonid = '<%=Button11.ClientID %>'; __doPostBack(buttonid,''); returnfalse; } } else { returntrue; } } </script></head><body><formid=&qu…

How To Handle an async postback timeout in ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" %> <script runat="server"> protectedvoid slow_postback(object sender, EventArgs e) { // ten seconds is overkill... we timeout after one second (see ScriptManager below) System.Threading.Thread.Sleep(10000); } </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Handling an async postback timeout</title> </head> <body> <form id="form1" runat="server"> <!-- This sets the timeout on async postbacks (i.e. UpdatePanel refreshes) to one second --> <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="1" /> <asp:UpdatePanel ID=&q…

GridView Tips and Trics

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridViewComplete.aspx.cs" Inherits="GridViewComplete" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headid="Head1"runat="server"><title>Grid View Add Update Delete</title></head><body><formid="form1"runat="server"><div><asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="Id"ShowFooter="true"AllowPaging="true"PageSize="4"AllowSorting="True"OnRowCommand="GridView1_RowCommand"OnPageIndexChanging="GridView1_PageIndexChanging"OnRowDeleting="GridView1_RowDeleting"OnRowEditing="GridView1_RowEditing"OnRow…

How To get IP Address to Country/State using www.hostip.info

using System; using System.Data; using System.Configuration; using System.Collections; 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.Net; using System.Text; publicpartialclass IpInfo : System.Web.UI.Page { protectedvoid Page_Load(object sender, EventArgs e) { string ipUrl = "http://www.hostip.info/api/get.html?ip=" + Request.UserHostAddress; WebClient webClient = new WebClient(); Byte[] ipInfoBytes = webClient.DownloadData(ipUrl); UTF8Encoding encoding = new UTF8Encoding(); string ipInfo = encoding.GetString(ipInfoBytes); Response.Write(ipInfo); } }

ModalPopupExtender Example for Editing Rows in a GridView (Master/Detail Scenario)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MasterDetail.aspx.cs" Inherits="MasterDetail" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>Untitled Page</title></head><body><formid="form"runat="server"><asp:ScriptManagerID="scriptManager"runat="server"/><div><asp:UpdatePanelID="updatePanel"runat="server"UpdateMode="Conditional"><ContentTemplate><asp:LabelID="lblTitle"runat="server"Text="Customers"BackColor="lightblue"Width="95%&quo…