Posted by: viralsarvaiya on: November 10, 2009
To get HTML of web page you need only few lines of code.
To start, place two TextBox controls named txtURL and txtPageHTML, and one button control on web form, like in image bellow:

Now, on button’s click event function, place this code:
[ C# ]
// We need these namespaces
using System;
using System.Text;
using System.Net;
public partial class DefaultCS : System.Web.UI.Page
{
protected void btnGetHTML_Click(object sender, EventArgs e)
{
// We’ll use WebClient class for reading HTML of web page
WebClient MyWebClient = new WebClient();
// Read web page HTML to byte array
Byte[] PageHTMLBytes;
if (txtURL.Text != “”)
{
PageHTMLBytes = MyWebClient.DownloadData(txtURL.Text);
// Convert result from byte array to string
// and display it in TextBox txtPageHTML
UTF8Encoding oUTF8 = new UTF8Encoding();
txtPageHTML.Text = oUTF8.GetString(PageHTMLBytes);
}
}
}
[ VB.NET ]
‘ We need these namespaces
Imports System
Imports System.Text
Imports System.Net
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btnGetHTML_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetHTML.Click
‘ We’ll use WebClient class for reading HTML of web page
Dim MyWebClient As WebClient = New WebClient()
‘ Read web page HTML to byte array
Dim PageHTMLBytes() As Byte
If txtURL.Text <> “” Then
PageHTMLBytes = MyWebClient.DownloadData(txtURL.Text)
‘ Convert result from byte array to string
‘ and display it in TextBox txtPageHTML
Dim oUTF8 As UTF8Encoding = New UTF8Encoding()
txtPageHTML.Text = oUTF8.GetString(PageHTMLBytes)
End If
End Sub
End Class
Now you can start sample project, type some valid URL in first TextBox control and click to “btnGetHTML” button. Code listed above will return HTML code of requested URL and display it in second text box, like in image bellow:

As you see, loading of HTML code of web page is relatively easy. Analyzing of this data is much harder and depends of page structure.
Reference :
http://www.beansoftware.com/ASP.NET-FAQ/Read-Page-HTML.aspx
Posted by: viralsarvaiya on: November 4, 2009
select * from information_schema.constraint_column_usage
This Query give the list of the table with the constraint
select * from information_schema.referential_constraints
this query give the list of the table with the foreign key constraint
now the query to find the relations
select
tblAll.table_name as Primary_TableName,
tblAll.column_name as Primary_TableColumn,
tblFK.table_name as ForeignKey_TableName,
tblFK.column_name as ForeignKey_ColumnName
from information_schema.constraint_column_usage tblAll
inner join information_schema.referential_constraints tblAllFK on
tblAllFK.unique_constraint_name = tblAll.constraint_name
inner join information_schema.constraint_column_usage tblFK on
tblAllFK.constraint_name=tblFK.constraint_name
Enjoy coding…..
Posted by: viralsarvaiya on: November 4, 2009
I had been searching for a way to merge cells in a GridView
If e.Row.DataItemIndex % 2 = 0 Then
e.Row.Cells(0).RowSpan = 2
e.Row.Cells(1).RowSpan = 2
End If
‘Remove the extra cells created due to row span for odd rows
If e.Row.DataItemIndex % 2 = 1 Then
e.Row.Cells.RemoveAt(0)
e.Row.Cells.RemoveAt(0)
e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Center
End If
This code should take every cell in the first and second columns and merge it with the cell directly below it. Of course, this should be used very carefully, because you could screw up your data if each record does not have another corresponding record with it. However, this shouldn’t be too difficult to program around by adding data checks.
Posted by: viralsarvaiya on: November 2, 2009
All the hype that once surrounded XML is finally starting to die down, and developers are really beginning to harness the power and flexibility of the language. XML is a data descriptive language that uses a set of user-defined tags to describe data in a hierarchically-structured format.
The release of Microsoft SQL Server 2000 a couple of months ago saw Microsoft jump on the XML band-wagon too – they’ve included a number of different ways to manipulate data as well-formed XML. Firstly, there’s the SQL XML support. Microsoft’s implementation of SQL XML provides a simple configuration tools that allows developers to gain remote access to databases using URL based queries over HTTP. For example, we can setup an SQL XML virtual directory on our Web server named “myVirtual”. Then, assuming we have the appropriate security permissions, we can use any browser to query our database using a simple URL based query (such as: http://www.myserver.com/myVirtual?SQL=select+*+from+products+for+xml+auto). This then returns our results as an XML based recordset.
Notice the “for xml auto” part of our query above? This determines the way in which SQL Server 2000 shapes our data. There are three shaping methods:
1. “for xml auto”: Returns XML elements that are nested, based on which tables are listed in the “from” part of the query, and which fields are listed in the “select” part.
2. “for xml raw”: Returns XML elements with the “row” prefix (ex: “<row tProduct …>”). Each column in a table is represented as an attribute and null column values aren’t included.
3. “for xml explicit”: Explicit mode is the most complex shaping method used in SQL Server 2000. It allows users to query a data source in such a way that the names and values of the returned XML are specified before the query batch is executed.
for read detials click here
other links…
http://msdn.microsoft.com/en-us/library/ms345137%28SQL.90%29.aspx
Posted by: viralsarvaiya on: October 30, 2009
Steps.
1) Create Simple Web Application.
2) put the below control in to the page (.aspx)
2.1) GridView (id= GridView1)
2.2) Button (id=button1 and Text =Create CSV File)
3) assign data source to GridView
4) on the button_click event put the following code.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Try
‘Create CSV file
Dim objSw As New StreamWriter(Server.MapPath(“~/demo.csv”))
‘get table from GridView1
Dim objDt As DataTable = DirectCast(GridView1.DataSource, DataSet).Tables(0)
‘Get No Of Column in GridView
Dim NoOfColumn As Integer = objDt.Columns.Count
‘Create Header
For i As Integer = 0 To NoOfColumn – 1
objSw.Write(objDt.Columns(i))
‘check not last column
If i < NoOfColumn – 1 Then
objSw.Write(“,”)
End If
Next
objSw.Write(objSw.NewLine)
‘Create Data
For Each dr As DataRow In objDt.Rows
For i As Integer = 0 To NoOfColumn – 1
objSw.Write(dr(i).ToString())
If i < NoOfColumn – 1 Then
objSw.Write(“,”)
End If
Next
objSw.Write(objSw.NewLine)
Next
objSw.Close()
Catch ex As Exception
Response.Write(“Can Not Generate CSV File”)
End Try
End Sub
Enjoy Coding….
Posted by: viralsarvaiya on: October 29, 2009
This will find X and Y coordinates of the mouse where the mouse moves in browser.
<html>
<head>
<title>Get Mouse Coordinates</title>
<script language=”javascript”>
var divObj;
document.onmousemove=getMouseCoordinates;
function getMouseCoordinates(event)
{
ev = event || window.event;
divObj.innerHTML = “Mouse X:”+ev.pageX + ” Mouse Y:”+ev.pageY;
}
function loadDiv()
{
divObj = document.getElementById(“mouseCoord”);
}
</script>
</head>
<body onLoad=”loadDiv()”>
<div id=”mouseCoord”>Mouse Coordinates position will be displayed here.
</div>
</body>
</html>
Posted by: viralsarvaiya on: October 28, 2009
I have one CheckBoxList control that binds values at runtime from the database, and when I click on a button from the page, I want to get the values (Database Primary Key) from the CheckBoxList, but for the checked checkboxes only.
Here is the code, what I have achieved so far. This code works fine with IE 7, but I am not sure with the FireFox.
ASPX page: <asp:CheckBoxList ID=”CheckBoxList1″ runat=”server” OnDataBound=”CheckBoxList1_DataBound” >
<asp:ListItem Value=”First1″ Text=”First” ></asp:ListItem>
<asp:ListItem Value=”second2″ Text=”Second”></asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID=”Button1″ runat=”server” Text=”Button” />
<script language=”javascript” type=”text/javascript”>
function CheckItem()
{
var tbl = document.getElementById(‘<%= CheckBoxList1.ClientID %>’).childNodes[0];
for(var i=0; i<tbl.childNodes.length;i++)
{
for(var k=0; k<tbl.childNodes[i].childNodes.length; k++)
{
if(tbl.childNodes[i].childNodes[k].nodeName == “TD”)
{
var currentTD = tbl.childNodes[i].childNodes[k];
for(var j=0; j<currentTD.childNodes.length; j++)
{
if(currentTD.childNodes[j].nodeName == “SPAN”)
{
var currentSpan = currentTD.childNodes[j];
for(var l=0; l<currentSpan.childNodes.length; l++)
{
if(currentSpan.childNodes[l].nodeName == “INPUT” && currentSpan.childNodes[l].type == “checkbox”)
{
var currentChkBox = currentSpan.childNodes[l];
if(currentChkBox.checked)
{
alert(currentSpan.alt);
}
}
}
}
}
}
}
}
}
</script>
Code Behind:
Button1.Attributes.Add(“onclick”, “javascript:CheckItem();”);
CheckBoxList1.DataSource = <Your Dataset>;
CheckBoxList1.DataTextField = “PersonName”;
CheckBoxList1.DataValueField = “PersonID”;
CheckBoxList1.DataBind();
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
CheckBoxList chkList = (CheckBoxList)(sender);
foreach (ListItem item in chkList.Items)
{
item.Attributes.Add(“alt”, item.Value);
}
}
other way is as below….
this is run in FF as well as FF
function CheckItem() {
var tbl = document.getElementById(‘<%= CheckBoxList1.ClientID %>’);
var chkspecialCount = tbl.getElementsByTagName(“input”);
var chkspeciallbls = tbl.getElementsByTagName(“label”);
for (var i = 0; i < chkspecialCount.length; i++) {
if (chkspecialCount[i].checked == true) {
var str = chkspeciallbls[i].innerHTML;
alert(str);
}
}
}
Enjoy Coding….
Reference
http://hspinfo.wordpress.com/2008/08/14/get-checkboxlist-values-using-javascript/
Posted by: viralsarvaiya on: October 27, 2009
take a element of Div
<div id=”contentmsg” style=”position: absolute; right:25%; width: 100px; height:100px;visibility: hidden;”>
<img src=”images/loading.gif” width=”50px” height=”50px” />
</div>
suppose we have a dropdown and according to onchange() event this div is visible or hide,
<asp:DropDownList ID=”ddlparavalue” runat=”server”></asp:DropDownList>
in the server side bind the dropdownlist dynamically and add the attribultes as below
ddlparavalue.Attributes.Add(“onchange”, “javascript:void HideOrVisibleDDL();”)
in the head of the html section write the following code
<script language=”javascript” type=”text/javascript”>
function HideOrVisibleDDL() {
var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
var windowWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
var IpopTop = ((windowHeight – document.getElementById(“contentmsg”).offsetHeight) / 2);
document.getElementById(“contentmsg”).style.top = IpopTop + document.body.scrollTop;
document.getElementById(“contentmsg”).style.left = (document.body.clientWidth / 2) – 50;
document.getElementById(“contentmsg”).style.visibility = “visible”;
}
</script>
in some case it is not working just becouse of the DOCType tag so please remove the DOCTYPE tag as like below
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
so remove this tag.
enjoy coding….
Posted by: viralsarvaiya on: October 26, 2009
What ist the UpdatePanel in ASP.NET Ajax? The answer is easy: When adding an UpdatePanel-control to your page, you can achieve a partial-update of your page on a postback. Only the content in the UpdatePanel is refreshed, the other parts of the page remain unchanged. This topic explains, how you can setup an Ajax-enabled project and use the UpdatePanel control.
for more details click below….
http://www.asp.net/Ajax/Documentation/Live/tutorials/IntroductionUpdatePanel.aspx
http://www.codegod.de/WebAppCodeGod/UpdatePanel-tutorial-ASP-NET-AJAX-AID281.aspx
Recent Comments