Sunday, January 31, 2010

Check / Unheck all checkboxes of HTML Table

Lets we have a HTML Table whose id=tblemail and it contain many rows and every row contains a check box.. and this HTML table contains check box in its header.. so when i click on checkbox of header then all checkboxes of rows of that table should be checked/ unchecked according to check box in header...

< table id="tblemail" border="1" style="text-align: left" width="80%" class="border" >
< tr >
< th >
Select Your choices
< /th >
< th >
< asp:CheckBox ID="cbSelectAll" runat="server" / >
< /th >
< /tr >
< tr >
< td >
I want to send message
< /td >
< td >
< asp:CheckBox ID="chkmsg" runat="server" / >
< /td >
< /tr >
< tr >
< td >
i want to receive message
< /td >
< td >
< asp:CheckBox ID="chkrcvmsg" runat="server" / >
< /td >
< /tr >

< /table >




below is java script function code to check/uncheck all checkboxes of a HTML table:
< script language="javascript" type="text/javascript" >

function SelectAll(id) {

var frm = document.getElementById('tblemail').getElementsByTagName("input");
var len = frm.length;

for (i=0;i< len;i++)
{
if (frm[i].type == "checkbox")
{
frm[i].checked = document.getElementById(id).checked;
}
}


}

< /script >



add below line in page_load so that it will add click event to selectall check box:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If (Not IsPostBack) Then
cbSelectAll.Attributes.Add("onclick", "javascript:SelectAll('" & cbSelectAll.ClientID & "')")
end if
end sub
Read More

Friday, January 29, 2010

What is the difference between Server.Transfer and Response.Redirect? Why would I choose one over the other?

Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user's browser to another page or site. This performas a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.
Read More

What methods are fired during the page load?

Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.
Read More

What is the difference between Response.Write() andResponse.Output.Write()?

Response.Output.Write() allows you to write formatted output.
for eg:
it is very similer to console.write which we use in c#.net(console programming)
we use place holders for formated output...

Response.Output.Write("

Item: {0}, Cost: ${1}

",item.Description, item.Cost);
Read More

What is the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process?

inetinfo.exe is the Microsoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request to the actual worker process aspnet_wp.exe.

actually mainly inetinfo.exe:
Inetinfo.exe is the ASP.Net request handler that handles the requests from the client .If it's for static resources like HTML files or image files inetinfo.exe process the request and sent to client. If the request is with extension aspx/asp, inetinfo.exe processes the request to API filter.
Read More

What is the maximum possible length of a query string?

Many of times this question have been asked while interview or we also should know that how much characters a query string can contain....

Although the specification of the HTTP protocol does not specify any maximum length, practical limits are imposed by web browser and server software.

Microsoft Internet Explorer (Browser)

Microsoft states that the maximum length of a URL in Internet Explorer is 2,083 characters, with no more than 2,048 characters in the path portion of the URL. In my tests, attempts to use URLs longer than this produced a clear error message in Internet Explorer.

Firefox (Browser)

After 65,536 characters, the location bar no longer displays the URL in Windows Firefox 1.5.x. However, longer URLs will work. I stopped testing after 100,000 characters.

Safari (Browser)

At least 80,000 characters will work. I stopped testing after 80,000 characters.

Opera (Browser)

At least 190,000 characters will work. I stopped testing after 190,000 characters. Opera 9 for Windows continued to display a fully editable, copyable and pasteable URL in the location bar even at 190,000 characters.

Apache (Server)

My early attempts to measure the maximum URL length in web browsers bumped into a server URL length limit of approximately 4,000 characters, after which Apache produces a "413 Entity Too Large" error. I used the current up to date Apache build found in Red Hat Enterprise Linux 4. The official Apache documentation only mentions an 8,192-byte limit on an individual field in a request.

Microsoft Internet Information Server (Server)

The default limit is 16,384 characters (yes, Microsoft's web server accepts longer URLs than Microsoft's web browser). This is configurable.

Perl HTTP::Daemon (Server)

Up to 8,000 bytes will work. Those constructing web application servers with Perl's HTTP::Daemon module will encounter a 16,384 byte limit on the combined size of all HTTP request headers. This does not include POST-method form data, file uploads, etc., but it does include the URL. In practice this resulted in a 413 error when a URL was significantly longer than 8,000 characters. This limitation can be easily removed. Look for all occurrences of 16x1024 in Daemon.pm and replace them with a larger value. Of course, this does increase your exposure to denial of service attacks.
Read More

Wednesday, January 27, 2010

Date Difference in JavaScript

Read More

Tuesday, January 19, 2010

Make HTML textbox readonly

to make html textbox readonly follow below steps:
make Html textbox runat="server"

and in codding write
txtname.Disabled = True
Read More

Monday, January 18, 2010

Optional Nullable Parameter introduced in VB.NET 10

In previous editions like .net framework 2.0/3.0/3.5 we were not able to create a Optional parameter as a nullable in vb.net. but now its time to get happy. you can create Nullable Optional Parameter in VB.NET 10.

eg:

Sub MyFunc(ByVal _name As String, ByVal _email As String, Optional ByVal _age As Integer? = Nothing)
your code
end sub



Benefit: The benefit of Nullable Optional Parameter is that if you want to pass value then it will take value if you will not pass value then it will take 'Nothing' in that parameter then before using that parameter you can easily check that value is Nothing or not

like:

if _age isnot Nothing then
your code
end if
Read More

Thursday, January 14, 2010

Improve Query Performance using "With" Clause

Using with clause we can improve query performance.
Read complete Article
Read More

Tuesday, January 12, 2010

Open popup window using JavaScript

if we want to open a popup window using javascript we can do it by using following function:
javascript:showWindow('mypage.aspx"',800,600,50)

How to use it?

if you want to open popup window using Anchor tag of Html:
< a href='javascript:showWindow('mypage.aspx"',800,600,50)' >click me< /a >

open popup window using Html Button:

< input type="button" id="btnmap" name="btnmap" value="Map" onclick ='javascript:showWindow(< %# """MapDSHotelDetail.aspx?hotelname=" &container.dataitem("hotelname")& "&cityid=" & container.dataitem("cityid") & "&countryid=" & ddlcountry.selectedvalue &"""" % >,800,600)'/ >
Read More

Colors in CSS

If you are not a regular regular designer or you don't remember names of different colors provided by CSS.Then this is list of all Mostly used colors of CSS:































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Color NameHEXColorShadesMix
AliceBlue #F0F8FF
ShadesMix
AntiqueWhite #FAEBD7
ShadesMix
Aqua #00FFFF
ShadesMix
Aquamarine #7FFFD4
ShadesMix
Azure #F0FFFF
ShadesMix
Beige #F5F5DC
ShadesMix
Bisque #FFE4C4
ShadesMix
Black #000000
ShadesMix
BlanchedAlmond #FFEBCD
ShadesMix
Blue #0000FF
ShadesMix
BlueViolet #8A2BE2
ShadesMix
Brown #A52A2A
ShadesMix
BurlyWood #DEB887
ShadesMix
CadetBlue #5F9EA0
ShadesMix
Chartreuse #7FFF00
ShadesMix
Chocolate #D2691E
ShadesMix
Coral #FF7F50
ShadesMix
CornflowerBlue #6495ED
ShadesMix
Cornsilk #FFF8DC
ShadesMix
Crimson #DC143C
ShadesMix
Cyan #00FFFF
ShadesMix
DarkBlue #00008B
ShadesMix
DarkCyan #008B8B
ShadesMix
DarkGoldenRod #B8860B
ShadesMix
DarkGray #A9A9A9
ShadesMix
DarkGreen #006400
ShadesMix
DarkKhaki #BDB76B
ShadesMix
DarkMagenta #8B008B
ShadesMix
DarkOliveGreen #556B2F
ShadesMix
Darkorange #FF8C00
ShadesMix
DarkOrchid #9932CC
ShadesMix
DarkRed #8B0000
ShadesMix
DarkSalmon #E9967A
ShadesMix
DarkSeaGreen #8FBC8F
ShadesMix
DarkSlateBlue #483D8B
ShadesMix
DarkSlateGray #2F4F4F
ShadesMix
DarkTurquoise #00CED1
ShadesMix
DarkViolet #9400D3
ShadesMix
DeepPink #FF1493
ShadesMix
DeepSkyBlue #00BFFF
ShadesMix
DimGray #696969
ShadesMix
DodgerBlue #1E90FF
ShadesMix
FireBrick #B22222
ShadesMix
FloralWhite #FFFAF0
ShadesMix
ForestGreen #228B22
ShadesMix
Fuchsia #FF00FF
ShadesMix
Gainsboro #DCDCDC
ShadesMix
GhostWhite #F8F8FF
ShadesMix
Gold #FFD700
ShadesMix
GoldenRod #DAA520
ShadesMix
Gray #808080
ShadesMix
Green #008000
ShadesMix
GreenYellow #ADFF2F
ShadesMix
HoneyDew #F0FFF0
ShadesMix
HotPink #FF69B4
ShadesMix
IndianRed #CD5C5C
ShadesMix
Indigo #4B0082
ShadesMix
Ivory #FFFFF0
ShadesMix
Khaki #F0E68C
ShadesMix
Lavender #E6E6FA
ShadesMix
LavenderBlush #FFF0F5
ShadesMix
LawnGreen #7CFC00
ShadesMix
LemonChiffon #FFFACD
ShadesMix
LightBlue #ADD8E6
ShadesMix
LightCoral #F08080
ShadesMix
LightCyan #E0FFFF
ShadesMix
LightGoldenRodYellow #FAFAD2
ShadesMix
LightGrey #D3D3D3
ShadesMix
LightGreen #90EE90
ShadesMix
LightPink #FFB6C1
ShadesMix
LightSalmon #FFA07A
ShadesMix
LightSeaGreen #20B2AA
ShadesMix
LightSkyBlue #87CEFA
ShadesMix
LightSlateGray #778899
ShadesMix
LightSteelBlue #B0C4DE
ShadesMix
LightYellow #FFFFE0
ShadesMix
Lime #00FF00
ShadesMix
LimeGreen #32CD32
ShadesMix
Linen #FAF0E6
ShadesMix
Magenta #FF00FF
ShadesMix
Maroon #800000
ShadesMix
MediumAquaMarine #66CDAA
ShadesMix
MediumBlue #0000CD
ShadesMix
MediumOrchid #BA55D3
ShadesMix
MediumPurple #9370D8
ShadesMix
MediumSeaGreen #3CB371
ShadesMix
MediumSlateBlue #7B68EE
ShadesMix
MediumSpringGreen #00FA9A
ShadesMix
MediumTurquoise #48D1CC
ShadesMix
MediumVioletRed #C71585
ShadesMix
MidnightBlue #191970
ShadesMix
MintCream #F5FFFA
ShadesMix
MistyRose #FFE4E1
ShadesMix
Moccasin #FFE4B5
ShadesMix
NavajoWhite #FFDEAD
ShadesMix
Navy #000080
ShadesMix
OldLace #FDF5E6
ShadesMix
Olive #808000
ShadesMix
OliveDrab #6B8E23
ShadesMix
Orange #FFA500
ShadesMix
OrangeRed #FF4500
ShadesMix
Orchid #DA70D6
ShadesMix
PaleGoldenRod #EEE8AA
ShadesMix
PaleGreen #98FB98
ShadesMix
PaleTurquoise #AFEEEE
ShadesMix
PaleVioletRed #D87093
ShadesMix
PapayaWhip #FFEFD5
ShadesMix
PeachPuff #FFDAB9
ShadesMix
Peru #CD853F
ShadesMix
Pink #FFC0CB
ShadesMix
Plum #DDA0DD
ShadesMix
PowderBlue #B0E0E6
ShadesMix
Purple #800080
ShadesMix
Red #FF0000
ShadesMix
RosyBrown #BC8F8F
ShadesMix
RoyalBlue #4169E1
ShadesMix
SaddleBrown #8B4513
ShadesMix
Salmon #FA8072
ShadesMix
SandyBrown #F4A460
ShadesMix
SeaGreen #2E8B57
ShadesMix
SeaShell #FFF5EE
ShadesMix
Sienna #A0522D
ShadesMix
Silver #C0C0C0
ShadesMix
SkyBlue #87CEEB
ShadesMix
SlateBlue #6A5ACD
ShadesMix
SlateGray #708090
ShadesMix
Snow #FFFAFA
ShadesMix
SpringGreen #00FF7F
ShadesMix
SteelBlue #4682B4
ShadesMix
Tan #D2B48C
ShadesMix
Teal #008080
ShadesMix
Thistle #D8BFD8
ShadesMix
Tomato #FF6347
ShadesMix
Turquoise #40E0D0
ShadesMix
Violet #EE82EE
ShadesMix
Wheat #F5DEB3
ShadesMix
White #FFFFFF
ShadesMix
WhiteSmoke #F5F5F5
ShadesMix
Yellow #FFFF00
ShadesMix
YellowGreen #9ACD32
ShadesMix
Read More

Monday, January 11, 2010

Refresh Current Page Using Asp.net Code

below code can be use to refresh the current page at server side event:

Page.Response.Redirect(Page.Request.Url.ToString(), true);
Read More

Refresh Current Page using JavaScript

Sometimes we need to refresh our current page by clicking on some button (not refresh button of browser). To refresh page you need to call below function:

function refreshMe()
{
location.reload(true);
}
Read More

Refresh Parent Page from Popup/child page

some time we have a datagrid/gridview in parent form and we add new values or we remove value from existing grid by using a popup from and we want that when we finish our add/delete/update from popup/child page my parent form should automatically get refresh so i can see the changes i have done in popup form.
write the following code in your page:

< script language="javascript" type="text/javascript" >
function closeme()
{
opener.location.reload();
window.close();
}
< /script >


< input id="btnClose" class="form-button" onclick="closeme()" type="button" value="Close" / >
Read More

Sunday, January 10, 2010

Select single Radio in DataGrid using JavaScript

some times we need to select a single row from a grid and for that we place a extra column in it. which contain a radio button in it. and we want that only one radio of that column should be selected. so to select single radio button in Grid using JavaScript (client side script) we need to write below code:

if your radio is 'runat="Server"' then below code will help you.
java Script function:

< script language="javascript" type="text/javascript" >
function selectOne(rdoId,gridName)
{
var rdo = document.getElementById(rdoId);
/* Getting an array of all the "INPUT" controls on the form.*/
var all = document.getElementsByTagName("input");
for(i=0;i< all.length;i++)
{
/*Checking if it is a radio button, and also checking if the
id of that radio button is different than "rdoId" */
if(all[i].type=="radio" && all[i].id != rdo.id)
{
var count=all[i].id.indexOf(gridName);
if(count!=-1)
{
all[i].checked=false;
}
}
}
rdo.checked=true;/* Finally making the clicked radio button CHECKED */
}

< /script >


Below is code for grid:
< asp:GridView ID="datagrid1" runat="server" AutoGenerateColumns="false" >
< Columns >
< asp:TemplateField HeaderText="Select" >
< ItemTemplate >
< asp:RadioButton id="rdobutton" runat="server" OnClick="javascript:selectOne(this.id,'datagrid1');" >< /asp:RadioButton > < /ItemTemplate >
< /asp:TemplateField >
< /Columns >
< /asp:GridView >




======If your radio is not run at server===========
If your radio is not run at server then you just need to make ID and Name field as a same value and thats sit.. nothing to do extra... you will be able to select only one of then..
Read More

Friday, January 8, 2010

Show Data in Hindi Without Installing Font at Client Side

By using Unicode you can show data in any language without installing Font at client side.
for that you need to create a table in database and create a field with nvarchar datatype. then store your language data in that field. and directly show that data on page... it will not need any font to be installed
Read More

Wednesday, January 6, 2010

Show Asp.net Calender in Hindi



if you want to show asp.net calender in hindi as show above then you will have to do following:

< %@ Page Culture="hi-IN" uiculture="hi-IN" Language="vb"
% >
< html >
< head >
< title >Simple Sample - Hindi< /title >
< /head >
< body >
< form runat="Server" >
< asp:Calendar id="C1" runat="server"
DayNameFormat="Full" >< /asp:Calendar >
< /form >
< /body >
< /html >
Read More

Tuesday, January 5, 2010

Download any file or image from internet

If you have got URL of images and you want to download that files to your harddisk from internet then this function will help u:
NOTE: remember that your URL must contain protocol name like "http://"
eg: "http://www.mywebsite.com/aa.jpg"

My.Computer.Network.DownloadFile(Url, "c:\myfolder" & "\" & Url.Substring(url.LastIndexOf("/") + 1))

in above code "Url" is your file Url on internet
and second parameter is where you want to save file.. in above sample code it will get the file name from Url and save it in C:\myfolder with the same name as it was on internet
Read More

How to use controls in function used by Thread

When ever we tries to use any control from thread (function used by thread) then we will get following error:
Cross-thread operation not valid: Control 'ControlName' accessed from a thread other than the thread it was created on.

Solution:
For SETTING PROPERTY VALUE for any control below code will help u out from error:
Delegate Sub SetControlValueCallback(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)
Private Sub SetControlPropertyValue(ByVal oControl As Control, ByVal propName As String, ByVal propValue As Object)
If oControl.InvokeRequired Then
Dim d As New SetControlValueCallback(AddressOf SetControlPropertyValue)
oControl.Invoke(d, New Object() {oControl, propName, propValue})
Else
Dim t As Type = oControl.[GetType]()
Dim props As PropertyInfo() = t.GetProperties()
For Each p As PropertyInfo In props
If p.Name.ToUpper() = propName.ToUpper() Then
p.SetValue(oControl, propValue, Nothing)
End If
Next
End If
End Sub

call above code as:
to set value in lable:
SetControlPropertyValue(lablel1, "Text", "Hello")
To set value in progressbar:
SetControlPropertyValue(ProgressBar1, "value", i)


For SETTING FUNCTION VALUE for any control below code will help u out from error:
example for listbox:
Private Delegate Sub stringDelegate(ByVal s As String)
Private Sub AddItem(ByVal s As String)
If ListBox1.InvokeRequired Then
Dim sd As New stringDelegate(AddressOf AddItem)
Me.Invoke(sd, New Object() {s})
Else
ListBox1.Items.Add(s)
End If
End Sub

call above code by calling "AddItem()"
Read More

Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on

This error comes when you tries to add items in list box (or any other control) in thread (or from the function which is being used by thread).

Below is solution:

Private Delegate Sub stringDelegate(ByVal s As String)
Private Sub AddItem(ByVal s As String)
If ListBox1.InvokeRequired Then
Dim sd As New stringDelegate(AddressOf AddItem)
Me.Invoke(sd, New Object() {s})
Else
ListBox1.Items.Add(s)
End If
End Sub


now just pass your value in "AddItem()" and it will be added in listbox.
Read More

Basic Java Script Examples


lets we have a gridview as shown in pic. now we want have got rates of room and we want to select quantity in dropdownlist and on that basis we want to calculate total in last column of gridview. and then grand total in label below gridview.
then below javascript will help u out:





< script language="javascript" type="text/javascript" >
function ShowTotalPrices(selectbox) {

// var selectedStatus = dropDown.value;
//alert(selectedStatus);
var parentTr = selectbox.parentNode.parentNode;
var secondCellVal = parseInt ( parentTr.cells[4].innerText , 10 );
var comboVal = parseInt ( selectbox.value , 10 );

parentTr.cells[7].innerText = secondCellVal * comboVal;
ManipulateGrid();
}

function ManipulateGrid()
{
var gvDrv = document.getElementById("< %= GridView1.ClientID % >");
var gt=0.0;
for (i=1; i< gvDrv.rows.length; i++)
{
var cell = gvDrv.rows[i].cells;
var valold = cell[7].innerHTML;
var val = 0.0;
if(isNaN(parseFloat(valold)))
{
val= 0.0;
}
else
{
val = parseFloat(valold);
}

gt = parseFloat (gt) + val;
}
document.getElementById("lblgtamount").innerText=gt;
//lbl.Text = gt;
//alert(gt);
}

< /script >



in codding file write below code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim ddlroombook As DropDownList = CType(e.Row.FindControl("ddlbookroom"), DropDownList)
Dim availablerooms As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "NumberOfUnits"))
ddlroombook.Attributes.Add("onchange", "javascript:ShowTotalPrices(this);")
Dim i As Integer
For i = 0 To availablerooms
ddlroombook.Items.Add(i)
Next
End If
End Sub
Read More
Powered By Blogger · Designed By Seo Blogger Templates