Oct 06
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientSideCalcGridview.aspx.cs"
Inherits="ClientSideCalcGridview" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" id="indexText" />
<input type="button" id="showButton"
value="Show Array Element By Index"
onclick="ShowItem(document.getElementById('indexText').value);" />
</div>
</form>
</body>
<script type="text/javascript">
function ShowItem(index)
{
alert('myArray['+index+'] = ' + myArray[index]);
//alert(myArray[index]);
}
</script>
</html>
using System;
using System.Data;
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 ClientSideCalcGridview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session.Clear();
DataSet ds = new DataSet();
if (Session["dt"] == null)
{
ds = c();
}
else
{
ds = Session["dt"] as DataSet;
}
foreach (DataRow dr in ds.Tables[0].Rows)
{
this.ClientScript.RegisterArrayDeclaration("myArray", "'" + dr["Address"].ToString() + "'");
}
}
public DataSet c()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Company");
DataRow dr;
dt.Columns.Add(new DataColumn("accountNo", typeof(Int32)));
dt.Columns.Add(new DataColumn("CompanyName", typeof(string)));
dt.Columns.Add(new DataColumn("Address", typeof(string)));
for (int i = 0; i <= 10; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Company" + i + Environment.NewLine + "Title" + i;
dr[2] = "Address" + i.ToString();
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
Session["dt"] = dt;
return ds;
}
}
Oct 06
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
string[] ids = {"2343","2344","2345"};
string idString = String.Join(",",ids);
Response.Write(idString);
}
</script>
Oct 06
<html>
<head>
<script>
var aMember = [
["one", "1", "company 1"],
["one", "11", "company 11"],
["one", "111", "company 111"],
["two", "2", "company 2"],
["two", "22", "company 22"],
["three", "3", "company 3"],
["three", "33", "company 33"]];
function selCompany(theSel){
theForm = theSel.form;
opt = theForm.companies.options;
opt.length = 0;
if(theSel.value=="") return;
for(i=0;i<aMember.length;i++){
if(aMember[i][0]==theSel.value){
tValue = aMember[i][1];
tName = aMember[i][2];
for(j=0;j<opt.length;j++){
if(opt[j].value==tValue) tValue="";
}
if(tValue>""){
opt[opt.length] = new Option(tName, tValue);
}
}
}
}
</script>
</head>
<body>
<form>
Select company
<select name="sel" onchange="selCompany(this);" >
<option value="">-Please select-</option>
<option value="one"> one </option>
<option value="two"> two </option>
<option value="three"> three </option>
</select>
Companies:
<select name="companies">
</select>
</form>
</body>
</html>
Oct 06
Certain characters in your data will cause Javascript to crash. Special characters need to be handled with your server-side code. Below is a C# function that I create to do just such task.
<br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: Consolas, “Courier New”, Courier, Monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br /><br />.csharpcode pre { margin: 0em; }<br /><br />.csharpcode .rem { color: #008000; }<br /><br />.csharpcode .kwrd { color: #0000ff; }<br /><br />.csharpcode .str { color: #006080; }<br /><br />.csharpcode .op { color: #0000c0; }<br /><br />.csharpcode .preproc { color: #cc6633; }<br /><br />.csharpcode .asp { background-color: #ffff00; }<br /><br />.csharpcode .html { color: #800000; }<br /><br />.csharpcode .attr { color: #ff0000; }<br /><br />.csharpcode .alt<br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br /><br />.csharpcode .lnum { color: #606060; }<br />
protected string FormatForJS(object input) {
string data = input.ToString();
// cast the input to a string
data = data.Trim();
// replace those characters that will crash JAVASCRIPT
data = data.Replace("'", "\\'");
data = data.Replace("\n", "");
data = data.Replace("\r", "");
return data;
}
Oct 06
when you redirect your page the Request collection is undefined because you have
not requested anything.You can catch your referrer from javascript and the other
way is to use Querystring in code behind.
/>.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: black;<br /> font-family: Consolas, "Courier New", Courier, Monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br /><br />.csharpcode pre { margin: 0em; }<br /><br />.csharpcode .rem { color: #008000; }<br /><br />.csharpcode .kwrd { color: #0000ff; }<br /><br />.csharpcode .str { color: #006080; }<br /><br />.csharpcode .op { color: #0000c0; }<br /><br />.csharpcode .preproc { color: #cc6633; }<br /><br />.csharpcode .asp { background-color: #ffff00; }<br /><br />.csharpcode .html { color: #800000; }<br /><br />.csharpcode .attr { color: #ff0000; }<br /><br />.csharpcode .alt<br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br /><br />.csharpcode .lnum { color: #606060; }<br />
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JavascriptRedirection.aspx.cs" Inherits="JavascriptRedirection" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function Redirect(sTargetPageURL)
{
window.location.href = sTargetPageURL + "?previousPage=" +document.URL;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" runat="server" value="Redirect" onclick="Redirect('Redirect.aspx');" />
</div>
</form>
</body>
</html>
Oct 06
function setActiveTab(tabNumber)
{
var ctrl = $find(’<%=TabContainer.ClientID%>’);
ctrl.set_activeTab(ctrl.get_tabs()[tabNumber]);
}
this is a function that sets the active tab using javascript so you just set the anchor’s href to look like this:
<a href=’setActiveTab(1)’>Go to Next Tab;
Sep 09
let us supposed that you have a textbox is clicked, you need the text that says “Enter your search
here” to dissappear. This is the javascript for this?.
<asp:TextBox ID="TextBox1" runat="server" Text="Search Here"
onkeydown="if (this.value == 'Search Here') this.value = '';"
onclick="this.value=''"></asp:TextBox>
Aug 22
if you often use shortcut keys to navigate the web or any other
program for that matter, you probably expect the ESC key to close
popups and message boxes (alerts).When using popup windows on the web,
this is however not the case. If you use popups to show full sized images
of thumbnails, it would be natural to press the ESC key in the expectation
of the popup to close.To achieve this functionality, we have to place a little
JavaScript in the popup window. Add the following to the head section
of the html page:
<script type=”text/javascript”>
function ESCclose(evt) {
if (evt.keyCode == 27)
window.close();
}
</script>
Then add an onkeypress attribute in the body tag, like this:
<body onkeypress=”ESCclose(event)”>
That’s all it takes and it’s cross-browser compatible.
Aug 22
1) Create function definition
<head>
<script language=”Javascript”>
function resolution()
{
UserWidth = window.screen.availWidth
UserHeight = window.screen.availheight
window.resizeTo(UserWidth, UserHeight)
window.moveTo(0,0)
}
</script>
</head>
2) Call the function on load event of body.
<body OnLoad=”resolution();”>
Aug 11
This article has been posted at online dating site architect which providesfree online dating service and hosts Dating Idol Contests.
1.Create a New Project in VS.net and add a Button control
2.Copy the following javascript code in the header of the Page
//This function Creates the clone of the file upload control to upload images when clicked on AddAnother link.
//The function first get the reference of the file upload control “myElement1″ added in HTML and the refernce
//of the td where we want to add the new control and then creates the clone of this referenced file upload.
//The vale attribute of this newly created control is set to null as it contains the value of previously entered.
//The unique id and name is assigned to it and then added in the TD. Before inserting the BR tag is also inserted
//so the the control should be added in next line.
function addImageFile()
{
var tdFileInputs = document.getElementById(’tdFileInputs’);
var fileInput=document.getElementById(”myElement1″);
var newFileInput = fileInput.cloneNode(false);
newFileInput.value = null;
newFileInput.id += ‘A’; // A unique id
newFileInput.name = newFileInput.id;
if(document.all)
{
var br = document.createElement(”
“);
tdFileInputs.appendChild(br);
}
tdFileInputs.appendChild(newFileInput);
return false;
}
3.Add The following code in the click event of the button
protected void btnSaveChanges1_Click(object sender, EventArgs e)
{
string baseImageLocation =Server.MapPath(”../UserImages\\”);
string BaseVideoLocation = Server.MapPath(”../UserVideos\\”);
HttpFileCollection files = Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string fileExt = Path.GetExtension(file.FileName).ToLower();
string fileName = Path.GetFileName(file.FileName);
if (fileName != “”)
{
if(fileExt == “.jpg” || fileExt == “.gif”)
file.SaveAs(baseImageLocation + fileName);
else
file.SaveAs(BaseVideoLocation + fileName);
}
}
}