Powered By Blogger

Search

Wednesday, September 10, 2008

Cross Domain Iframe Resize

Cross Domain iframe Resize


Domain A: Html Page
There we want add one dummy Html Page with JavaScript

Dummy_Page.html
<html>
<head>
</head>
<body>
</body>
</html>
<script language="javascript" type="text/javascript">

var hashValue = window.location.hash
if ((hashValue != null) (hashValue.length != 0))
{
var pairs = hashValue.split('&');
if ((pairs != null) && (pairs.length > 0))
{
window.top.document.getElementById((pairs[1].split('='))[1]).style.height =(pairs[0].split('='))[1] +"px";
}
}
</script>

Domain A: Iframe Page

<html>
<head>
</head>
<body>
<table class="content" align="center" width="845">
<tbody>
<tr>
<td align="center" valign="top">

<iframe id="Home" scrolling="auto" frameborder="0" name="HOME" style="width: 100%;" src="http://www.DomainB.com/Home.aspx" >
</iframe>
</td>
</tr>
</tbody>
</table>

<script language="javascript" type="text/javascript">
var iframe= document.getElementById("Home");
iframe.src=iframe.src +"#frameID="+ iframe.id +"&site=http://www.DomainA.com/Dummy_Page.html";
</script>
</body>
</html>

Domain B: Frameheight.js
This script file want to include in Domain B Pages

function call()
{
var hashValue = window.location.hash.substring(1);
if ((hashValue == null) (hashValue.length == 0))
{ }
else
{
var pairs = hashValue.split('&');
if ((pairs != null) && (pairs.length > 0))
{
var iframeID = (pairs[0].split('='))[1];
var parlocation = (pairs[1].split('='))[1];
manage(iframeID,parlocation)
return;
}
}
setTimeout("call()",10);
}
function manage(iframeID,parlocation)
{
set_cookie("iframeID",iframeID);
set_cookie("location",parlocation);
document.getElementById("Home_sub").src=parlocation + "#Height=" + (document.body.offsetHeight+30) + "&iframeID=" + iframeID;
}

if( get_cookie("iframeID") != null && get_cookie("location") != null)
{
document.getElementById("Home_sub").src= get_cookie("location")+ "#Height=" + (document.body.offsetHeight+30) + "&iframeID=" + get_cookie("iframeID");
}
else
{
call();
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
var cookie_string = name + "=" + escape ( value );

if ( exp_y )
{
var expires = new Date ( exp_y, exp_m, exp_d );
cookie_string += "; expires=" + expires.toGMTString();
}

if ( path )
cookie_string += "; path=" + escape ( path );

if ( domain )
cookie_string += "; domain=" + escape ( domain );

if ( secure )
cookie_string += "; secure";

document.cookie = cookie_string;
}
function get_cookie ( cookie_name )
{
var results = document.cookie.match ( '(^;) ?' + cookie_name + '=([^;]*)(;$)' );

if ( results )
return ( unescape ( results[2] ) );
else
return null;
}




Domain B: All Pages(HTML , ASPX ,etc....)

(Red color Marked Code want to insert in all the pages)

<html>
<head>
</head>
<body>
<table class="content" align="center" width="845">
<tbody>
<tr>
<td align="center" valign="top"&gt
;<div style="padding:4px;border:solid 1px #cccccc;width:300px">
</div>
<div style="padding:4px;border:solid 1px #cccccc;width:300px">
</div>
</td>
</tr>
</tbody>
</table>
</form>

<iframe id="Home_sub" frameborder="0" name="home_sub" style="height:1px;width:1px;" src="">
</iframe>

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

</body>
</html>







Thursday, June 5, 2008

Post Data to Other website use Asp.net

Post Data to Other website use Asp.net

Programmatically full up other site textboxes and submit that page using asp.net

String strresponse="";
String postData = "login=user&password=pass123";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);


HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.test.com/login.aspx");


request.Method = "POST";
request.Accept = "test/html";
request.AllowAutoRedirect = true;
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;

request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream newStream = request.GetRequestStream();

newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();

request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream receiveStream = response.GetResponseStream();

StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);


strresponse = readStream.ReadToEnd();

Response.Write(strresponse);
readStream.Close();
response.Close();

Clearing Recent Projects list in Visual Studio 2005

Clearing Recent Projects list in Visual Studio 2005

If you had a list of projects listed on the Visual Studio 2005 Home page's Recent Projects section and wanted to clear any of these items, there is not a way to do it using the IDE.

You will need to go to the registry (Start->Run->regedit) and
remove entries from:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList

Thursday, April 17, 2008

ASP.NET 2.0 GridView control in Paging and Sorting

ASP.NET 2.0 GridView control in Paging and Sorting
This article will describe how you can manually implement paging and sorting for the new GridView control in ASP.NET 2.0

First of all I set the AlowPaging and AllowSorting properties to true, then specified page PageSize attribute of GridView to 10. For each bound Column (that I want to be sorted) I specified the SortExpression attribute same as the column name in the database table.

After doing these initial changes you need to handle the Sorting event. There are two events for sorting one is Sorting and the other is Sorted. Sorted is called just after the GridView is sorted and it’s the Sorting event in which you will need to handle the sorting logic.

Here a GridViewSortEventArgs is provided from which you can get the column’s SortExpression and SortDirection. You will need to re fetch the data from database and bind that to the GridView and you need to restructure the query with order by and DESC or ASC clauses.

For Paging there is the event PageIndexChanging that gives the index of the new page clicked. Here you just need to set the PageIndex property of the GridView to the new Index and re bind the data to GridView.

Design Page :



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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Grid View Sorting</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" OnPageIndexChanging="GridView1_PageIndexChanging"
OnSorting="GridView1_Sorting" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ProjectID" HeaderText="ProjectID" SortExpression="ProjectID" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="ShortName" HeaderText="ShortName" SortExpression="ShortName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="EstimatedStartDate" HeaderText="EstimatedStartDate" SortExpression="EstimatedStartDate"/>
</Columns>

</asp:GridView>
<asp:HiddenField ID="Direction" runat="server" />
<asp:HiddenField ID="Expression" runat="server" />
</div>
</form>
</body>
</html>



Code Page :

using System;
using System.Data;
using System.Data.SqlClient;
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;

public partial class GridViewTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridView1.DataSource = DataBinder().Tables[0];
GridView1.DataBind();
Direction.Value= "ASC";
}
}
public DataSet DataBinder()
{
SqlConnection con = new SqlConnection("Data Source=Test;Initial Catalog=TESTDB_Dev;User ID=User;Password=Pass");
con.Open();
SqlDataAdapter adp = new SqlDataAdapter("Select ProjectID, Name ,ShortName ,Description, StartDate from Project", con);
DataSet ds = new DataSet();
adp.Fill(ds);
return ds;
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
Expression.Value= e.SortExpression;
if (Direction.Value!=("ASC"))
{
Direction.Value= "ASC";
}
else
{
Direction.Value= "DESC";
}
Sort(Expression.Value+" "+ Direction.Value);
}

public void Sort(string Exp)
{
DataView DV = new DataView(DataBinder().Tables[0]);
try
{
DV.Sort = Exp;
}
catch (Exception ex)
{

}
GridView1.DataSource = DV;
GridView1.DataBind();
}


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Sort(Expression.Value+ " " + Direction.Value);
}
}



Monday, April 7, 2008

Relation objects in a dataset

How to use relation objects in a dataset?
DataSet's that contain multiple DataTable objects can use DataRelation objects to relate one table to another. Adding a DataRelation to a DataSet adds by default a UniqueConstraint to the parent table and a ForeignKeyConstraint to the child table.
The code sample below creates a DataRelation using two DataTable objects in a DataSet. Each DataTable contains a column named CustID which serves as a "relation" between two the DataTable objects. The example adds a single DataRelation to the Relations collection of the DataSet. The first argument in the sample specifies the name of the DataRelation being created. The second argument sets the parent DataColumn and the third argument sets the child DataColumn.

custDS.Relations.Add("CustOrders",custDS.Tables["Customers"].Columns["CustID"],custDS.Tables["Orders"].Columns["CustID"]);
OR

private void CreateRelation()
{
DataColumn parentCol;DataColumn childCol;
parentCol = DataSet1.Tables["Customers"].Columns["CustID"];
childCol = DataSet1.Tables["Orders"].Columns["CustID"];
DataRelation relCustOrder;
relCustOrder = new DataRelation("CustomersOrders", parentCol, childCol);
DataSet1.Relations.Add(relCustOrder);