We all know that to get the current URL of the browser for an Web Application can be find by
HttpContext.Current.Request.Url.AbsolutePath
But to find out the current URL of IE from a C# application following scripts can be useful
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.WebBrowser ies in shellWindows)
{
Console.WriteLine(ies.LocationURL);
}
Windows PowerShell 2.0 Best Practices (Best Practices (Microsoft))
First of all add reference the SHDocVw.dll to the apllication.
object o = null;
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
IWebBrowserApp wb = (IWebBrowserApp)ie;
wb.Visible = true;
//Do anything else with the window here that you wish
wb.Navigate("http://google.com", ref o, ref o, ref o, ref o);
Internet Explorer 8, Illustrated Essentials
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.IO;
using System.Xml.Serialization;
/// <summary>
/// Summary description for Serialization
/// </summary>
public class Serialization
{
public static string StringSerialize(object instance)
{
MemoryStream m = new MemoryStream();
XmlSerializer x = new XmlSerializer(instance.GetType());
x.Serialize(m, instance);
byte[] b = m.ToArray();
string s = System.Text.ASCIIEncoding.ASCII.GetString(b);
return s;
}
public static byte[] ByteSerialize(object instance)
{
MemoryStream m = new MemoryStream();
XmlSerializer x = new XmlSerializer(instance.GetType());
x.Serialize(m, instance);
byte[] b = m.ToArray();
return b;
}
public static object DeSerialize(string Text, Type type)
{
byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(Text);
MemoryStream m = new MemoryStream(b);
XmlSerializer x = new XmlSerializer(type);
object o = x.Deserialize(m);
return o;
}
public static object DeSerialize(byte[] b, Type type)
{
MemoryStream m = new MemoryStream(b);
XmlSerializer x = new XmlSerializer(type);
object o = x.Deserialize(m);
return o;
}
}
Ajax, Update Panel, Script Manager, Update Controls Outside Update Panel With Out Postback
Sen Thomas
Here my first post is regarding Ajax.
So here I am going to give you a simple example how to update the controls outside the update panel without postback
Code behind file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class scriptMgr : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Label1 upadte" + DateTime.Now.ToString();
Label2.Text = "Label2 updated" + DateTime.Now.ToString();
if (ScriptManager1.IsInAsyncPostBack)
{
ScriptManager1.RegisterDataItem(Label3, DateTime.Now.ToString());
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "Label1 " + DateTime.Now.ToString();
Label2.Text = "Label2 " + DateTime.Now.ToString();
if (ScriptManager1.IsInAsyncPostBack)
{
ScriptManager1.RegisterDataItem(Label3, "Label3 "+DateTime.Now.ToString());
}
}
}
Aspx page
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);
function PageLoadingHandler(sender, args) {
var dataItems = args.get_dataItems();
if ($get('Label3') != null)
$get('Label3').innerHTML = dataItems['Label3'];
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Label ID="Label3" runat="server" Text="krwelkr"></asp:Label>
<asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
</div>
You can find Ajax Books
Professional ASP.NET 3.5 AJAX (Wrox Programmer to Programmer)
Microsoft ASP.NET and AJAX: Architecting Web Applications (PRO-Developer)
Here I will give one very simple linq sample code.
A query that will return each of the items in the people List collection by aliasing the people collection with a variable p and then selecting p (p is of type string remember as the people List is a collection of immutable string objects).
You may notice that query is of type IEnumerable - this is because we know that query will hold an enumeration of type string. When we foreach through the query the GetEnumerator of query is invoked.
protected void Page_Load(object sender, EventArgs e)
{
List
"Sen", "Paulose", "Thomas", "Raju",
"Anil", "Shyam", "Saidwin"
};
IEnumerable
foreach (string person in query)
{
Response.Write(person);
}
}
