Thursday, December 16, 2010
JavaScript Basics
var win = window.open('http://www.yahoo.com');
<input type="button" value="View" onclick="window.location = 'view-source:'+ 'http://www.royh.cn/'" />
IE version:
Clipboard(Copy and Paste) in ASP.NET
javascript clipboardData Description
The clipboardData object (accessible as a property of a window or frame object) is a temporary container that scripts in IE 5 and later for Windows can use to transfer text data, particularly during script-controlled operations that simulate cutting, copying, and pasting, or that control dragging. Your script controls what data is stored in the clipboardData object, such as just the text of an element, an element's entire HTML, or the URL of an image. For example, a page for children could display simple icon images of several different kinds of animals. If the user starts dragging the dog icon, the script initiated by the img element's onDragStart event handler stores a custom attribute value of that element (perhaps the URL of a pretty dog photo) into the clipboardData object. When the user drops the icon into the designated area, the onDrop event handler's function reads the clipboardData object's data and loads the photo image into position on the page. | |||
Data stored in this object survives navigation to other pages within the same domain and protocol. Therefore, you can use it to pass text data (including arrays that have been converted to strings by the Array.join( ) method) from one page to another without using cookies or location.search strings. But this is not the system clipboard (for security reasons). | |||
For more information on transferring data via this object and the event.dataTransfer object, visit http://msdn.microsoft.com/workshop/author/datatransfer/overview.asp. | |||
HTML Equivalent | |||
None. | |||
Object Model Reference | |||
[window.]clipboardData | |||
Object-Specific Properties | |||
| |||
Object-Specific Methods | |||
| |||
Object-Specific Event Handler Properties | |||
None. |
javascript clipboardData setData( )
setData(dataFormat, stringData) | |
Stores string data in the clipboardData object. Returns Boolean true if the assignment is successful | |
Parameters | |
| |
Returned Value | |
Boolean value: true | false. |
javascript clipboardData getData( )
getData(dataFormat) | |||||||||||||||||||
Returns a copy of data from the clipboardData object. The clipboardData contents remain intact for subsequent reading in other script statements. | |||||||||||||||||||
Parameters | |||||||||||||||||||
| |||||||||||||||||||
Returned Value | |||||||||||||||||||
String.javascript clipboardData clearData( )
javascript clipboardData dropEffect, effectAllowedThese two properties belong to the clipboardData object by inheritance from the dataTransfer object, to which they genuinely apply. Ignore these properties for the clipboardData object.Example :function SaveClipboardData(con) //Copy Clipboard Data from control... con is the control |
Tuesday, December 14, 2010
Datalist Customization by using Radiobuttons and Hyperlink by emailid requirement
here i need to design the following manner
Radiobutton To CC EmpRole-EmpFirsname EmpLastname(empemail@emp.com)
check the following image
Test.aspx:
==========
<asp:DataList runat="server" ID="emailaddress" Width="433px">
<ItemTemplate>
<asp:CheckBox ID="ToEmailCheck" runat="server" GroupName="rdbEmailAddress" AutoPostBack="true" OnCheckedChanged="EmailCheck_CheckedChanged"
EnableViewState="False" />
<asp:Label ID="lblRoleCode" runat="server"
Text='<%# Eval("cpx_cpo_code","-")%>' />
<asp:Label ID="lblFirstname" runat="server" Text='<%#Eval("ind_first_name") %>' />
<asp:Label ID="lblLastname" runat="server" Text='<%#Eval("ind_last_name") %>' />
<asp:HyperLink ID="TomailAddress" runat="server" Font-Underline="True" NavigateUrl='<%# Eval("cst_eml_address_dn", "mailto:{0}") %>'
Text='<%# Eval("cst_eml_address_dn", "({0})") %>' />
</ItemTemplate>
</asp:DataList>
here my requirement is i need to add the email address of the employees to the TOTextbox but it not fall in the CCTextbox
Test.aspx.cs:
=============
protected void EmailCheck_CheckedChanged(object sender, EventArgs e)
{
//txtCC.Text = string.Empty;
//txtTo.Text = string.Empty;
for (int i = 0; i < this.emailaddress.Items.Count; i++)
{
if (((CheckBox)emailaddress.Items[i].FindControl("CCEmailCheck")).Checked == true &&
((CheckBox)emailaddress.Items[i].FindControl("ToEmailCheck")).Checked == false)
{
// add to list
if (txtCC.Text.Length > 0)
{
string remove = txtTo.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtTo.Text = remove;
txtCC.Text += "," + ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString().TrimStart('(');
txtCC.Text = txtCC.Text.TrimEnd(')');
txtCC.Text = txtCC.Text.ToString();
}
else
{
string remove = txtTo.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtTo.Text = remove;
txtCC.Text += ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString();
txtCC.Text = txtCC.Text.TrimStart('(');
txtCC.Text = txtCC.Text.TrimEnd(')');
txtCC.Text = txtCC.Text.ToString();
}
}
else if (((CheckBox)emailaddress.Items[i].FindControl("ToEmailCheck")).Checked == true &&
((CheckBox)emailaddress.Items[i].FindControl("CCEmailCheck")).Checked == false)
{
if (txtTo.Text.Length > 0)
{
string remove = txtCC.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtCC.Text = remove;
txtTo.Text += "," + ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString().TrimStart('(');
txtTo.Text = txtTo.Text.TrimEnd(')');
txtTo.Text = txtTo.Text.ToString();
}
else
{
string remove = txtCC.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtCC.Text = remove;
txtTo.Text += ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString();
txtTo.Text = txtTo.Text.TrimStart('(');
txtTo.Text = txtTo.Text.TrimEnd(')');
txtTo.Text = txtTo.Text.ToString();
}
}
}
}
Radiobutton To CC EmpRole-EmpFirsname EmpLastname(empemail@emp.com)
check the following image
Test.aspx:
==========
<asp:DataList runat="server" ID="emailaddress" Width="433px">
<ItemTemplate>
<asp:CheckBox ID="ToEmailCheck" runat="server" GroupName="rdbEmailAddress" AutoPostBack="true" OnCheckedChanged="EmailCheck_CheckedChanged"
EnableViewState="False" />
<asp:Label ID="lblRoleCode" runat="server"
Text='<%# Eval("cpx_cpo_code","-")%>' />
<asp:Label ID="lblFirstname" runat="server" Text='<%#Eval("ind_first_name") %>' />
<asp:Label ID="lblLastname" runat="server" Text='<%#Eval("ind_last_name") %>' />
<asp:HyperLink ID="TomailAddress" runat="server" Font-Underline="True" NavigateUrl='<%# Eval("cst_eml_address_dn", "mailto:{0}") %>'
Text='<%# Eval("cst_eml_address_dn", "({0})") %>' />
</ItemTemplate>
</asp:DataList>
here my requirement is i need to add the email address of the employees to the TOTextbox but it not fall in the CCTextbox
Test.aspx.cs:
=============
protected void EmailCheck_CheckedChanged(object sender, EventArgs e)
{
//txtCC.Text = string.Empty;
//txtTo.Text = string.Empty;
for (int i = 0; i < this.emailaddress.Items.Count; i++)
{
if (((CheckBox)emailaddress.Items[i].FindControl("CCEmailCheck")).Checked == true &&
((CheckBox)emailaddress.Items[i].FindControl("ToEmailCheck")).Checked == false)
{
// add to list
if (txtCC.Text.Length > 0)
{
string remove = txtTo.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtTo.Text = remove;
txtCC.Text += "," + ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString().TrimStart('(');
txtCC.Text = txtCC.Text.TrimEnd(')');
txtCC.Text = txtCC.Text.ToString();
}
else
{
string remove = txtTo.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtTo.Text = remove;
txtCC.Text += ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString();
txtCC.Text = txtCC.Text.TrimStart('(');
txtCC.Text = txtCC.Text.TrimEnd(')');
txtCC.Text = txtCC.Text.ToString();
}
}
else if (((CheckBox)emailaddress.Items[i].FindControl("ToEmailCheck")).Checked == true &&
((CheckBox)emailaddress.Items[i].FindControl("CCEmailCheck")).Checked == false)
{
if (txtTo.Text.Length > 0)
{
string remove = txtCC.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtCC.Text = remove;
txtTo.Text += "," + ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString().TrimStart('(');
txtTo.Text = txtTo.Text.TrimEnd(')');
txtTo.Text = txtTo.Text.ToString();
}
else
{
string remove = txtCC.Text.Replace(((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString(), "");
txtCC.Text = remove;
txtTo.Text += ((HyperLink)emailaddress.Items[i].FindControl("TomailAddress")).Text.ToString();
txtTo.Text = txtTo.Text.TrimStart('(');
txtTo.Text = txtTo.Text.TrimEnd(')');
txtTo.Text = txtTo.Text.ToString();
}
}
}
}
Wednesday, November 17, 2010
Detect Browser Capabilities in ASP.NET
protected void Button1_Click(object sender, System.EventArgs e)
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
TextBox1.Text = s;
}
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
TextBox1.Text = s;
}
Creating control at runtime in C#Codebehind
private DataSet GetTemplatesDs()
{
con.Open();
string sqlToExecute = "select TemplateName,Subject from Template";
SqlDataAdapter da = new SqlDataAdapter(sqlToExecute, con);
DataSet ds = new DataSet();
da.Fill(ds, "Distribution_Mail_Template");
con.Close();
Session["TemplatesDs"] = ds;
return ds;
}
private void PopulateUI()//user defined function
{
Label[] additionalApplicants;
DataSet gettemplatesDs = GetTemplatesDs()
if (gettemplatesDs .Tables.Count > 0 && gettemplatesDs .Tables.Count > 0)
{
for (int i = 0; i < gettemplatesDs .Tables[0].Rows.Count; i++)
{
additionalApplicants = new Label[gettemplatesDs .Tables[0].Rows.Count];
additionalApplicants[i] = new Label();
additionalApplicants[i].ID = gettemplatesDs .Tables[0].Rows[0][""].ToString();
additionalApplicants[i].Text =gettemplatesDs .Tables[0].Rows[0][""].ToString();
this.Page.Controls.Add(additionalApplicants); //Adding controls to webpage
}
}
}
{
con.Open();
string sqlToExecute = "select TemplateName,Subject from Template";
SqlDataAdapter da = new SqlDataAdapter(sqlToExecute, con);
DataSet ds = new DataSet();
da.Fill(ds, "Distribution_Mail_Template");
con.Close();
Session["TemplatesDs"] = ds;
return ds;
}
private void PopulateUI()//user defined function
{
Label[] additionalApplicants;
DataSet gettemplatesDs = GetTemplatesDs()
if (gettemplatesDs .Tables.Count > 0 && gettemplatesDs .Tables.Count > 0)
{
for (int i = 0; i < gettemplatesDs .Tables[0].Rows.Count; i++)
{
additionalApplicants = new Label[gettemplatesDs .Tables[0].Rows.Count];
additionalApplicants[i] = new Label();
additionalApplicants[i].ID = gettemplatesDs .Tables[0].Rows[0][""].ToString();
additionalApplicants[i].Text =gettemplatesDs .Tables[0].Rows[0][""].ToString();
this.Page.Controls.Add(additionalApplicants); //Adding controls to webpage
}
}
}
Retain previously selected values by using Dictionary
Class1.cs:
=======
public void SaveSelectedOptions(Dictionary<string, string> selectedoptions)
{
Dictionary<string, string> tempDict = (Dictionary<string, string>)System.Web.HttpContext.Current.Session["SelectedValues"];
if (tempDict != null)
{
foreach (var pair in selectedoptions)
{
if (tempDict.ContainsKey(pair.Key)) // True
{
tempDict.Remove(pair.Key);
}
tempDict.Add(pair.Key, pair.Value);
}
System.Web.HttpContext.Current.Session["SelectedValues"] = tempDict;
}
else
{
Dictionary<string, string> newdict = new Dictionary<string, string>();
foreach (var pair in selectedoptions)
{
newdict.Add(pair.Key, pair.Value);
}
System.Web.HttpContext.Current.Session["SelectedValues"] = newdict;
}
}
Defaulst.aspx.cs
=============
private void saveSelectedOptions()
{
Dictionary<string, string> selectedoptionsDict = new Dictionary<string, string>();
selectedoptionsDict.Add(txtCompany.ID, txtCompany.Text);
selectedoptionsDict.Add(txtID.ID, txtID.Text);
selectedoptionsDict.Add(txtLastName.ID, txtLastName.Text);
selectedoptionsDict.Add(txtShowDays.ID, txtShowDays.Text);
selectedoptionsDict.Add(ddlAStatus.ID, ddlAStatus.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlChapterStatus.ID, ddlChapterStatus.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlDU.ID, ddlDU.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlPaid.ID, ddlPaid.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlRSatus.ID, ddlRSatus.SelectedIndex.ToString());
Class1.SaveSelectedOptions(selectedoptionsDict);
}
private void PopulatedPreSelectedOptions()
{
Dictionary<string, string> tempDict = (Dictionary<string, string>)Session["SelectedValues"];
if (tempDict != null)
{
foreach (var pair in tempDict)
{
string controlname = pair.Key;
Control control = this.FindControl(controlname);
if (control is DropDownList)
{
DropDownList drl = (DropDownList)this.FindControl(controlname);
drl.SelectedIndex = Convert.ToInt32(pair.Value);
}
else if (control is TextBox)
{
TextBox txt = (TextBox)this.FindControl(controlname);
txt.Text = pair.Value;
}
}
grvFiledsResult.DataSource = Session["SearchResultDS"];
grvFiledsResult.DataBind();
}
}
=======
public void SaveSelectedOptions(Dictionary<string, string> selectedoptions)
{
Dictionary<string, string> tempDict = (Dictionary<string, string>)System.Web.HttpContext.Current.Session["SelectedValues"];
if (tempDict != null)
{
foreach (var pair in selectedoptions)
{
if (tempDict.ContainsKey(pair.Key)) // True
{
tempDict.Remove(pair.Key);
}
tempDict.Add(pair.Key, pair.Value);
}
System.Web.HttpContext.Current.Session["SelectedValues"] = tempDict;
}
else
{
Dictionary<string, string> newdict = new Dictionary<string, string>();
foreach (var pair in selectedoptions)
{
newdict.Add(pair.Key, pair.Value);
}
System.Web.HttpContext.Current.Session["SelectedValues"] = newdict;
}
}
Defaulst.aspx.cs
=============
private void saveSelectedOptions()
{
Dictionary<string, string> selectedoptionsDict = new Dictionary<string, string>();
selectedoptionsDict.Add(txtCompany.ID, txtCompany.Text);
selectedoptionsDict.Add(txtID.ID, txtID.Text);
selectedoptionsDict.Add(txtLastName.ID, txtLastName.Text);
selectedoptionsDict.Add(txtShowDays.ID, txtShowDays.Text);
selectedoptionsDict.Add(ddlAStatus.ID, ddlAStatus.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlChapterStatus.ID, ddlChapterStatus.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlDU.ID, ddlDU.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlPaid.ID, ddlPaid.SelectedIndex.ToString());
selectedoptionsDict.Add(ddlRSatus.ID, ddlRSatus.SelectedIndex.ToString());
Class1.SaveSelectedOptions(selectedoptionsDict);
}
private void PopulatedPreSelectedOptions()
{
Dictionary<string, string> tempDict = (Dictionary<string, string>)Session["SelectedValues"];
if (tempDict != null)
{
foreach (var pair in tempDict)
{
string controlname = pair.Key;
Control control = this.FindControl(controlname);
if (control is DropDownList)
{
DropDownList drl = (DropDownList)this.FindControl(controlname);
drl.SelectedIndex = Convert.ToInt32(pair.Value);
}
else if (control is TextBox)
{
TextBox txt = (TextBox)this.FindControl(controlname);
txt.Text = pair.Value;
}
}
grvFiledsResult.DataSource = Session["SearchResultDS"];
grvFiledsResult.DataBind();
}
}
Monday, November 15, 2010
Creating Table dynamically in codebehind C#
.CS Code:
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("MemberType", typeof(string));
table.Rows.Add(membername, membertype);
table.Rows.Add(memberType);
DataSet myds = new DataSet();
myds.Tables.Add(table);
test.DataSource = myds;
test.DataBind();
.ASPX Code:
<table >
<tr><td>
<asp:GridView ID="test" AutoGenerateColumns="false" runat="server" ShowHeader="false" GridLines="None">
<Columns>
asp:BoundField DataField="Name" />
<asp:BoundField DataField="MemberType" />
</Columns>
</asp:GridView></td></tr></table>
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("MemberType", typeof(string));
table.Rows.Add(membername, membertype);
table.Rows.Add(memberType);
DataSet myds = new DataSet();
myds.Tables.Add(table);
test.DataSource = myds;
test.DataBind();
.ASPX Code:
<table >
<tr><td>
<asp:GridView ID="test" AutoGenerateColumns="false" runat="server" ShowHeader="false" GridLines="None">
<Columns>
asp:BoundField DataField="Name" />
<asp:BoundField DataField="MemberType" />
</Columns>
</asp:GridView></td></tr></table>
Subscribe to:
Posts (Atom)