Aug 11
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
using System.Collections;
using System.Web.UI;
namespace com.StadiumRoar.Utility
{

   public class Utilities
   {
       public static void OpenPopUp(System.Web.UI.WebControls.WebControl opener,
   string PagePath, string windowName, int width, int height)
       {
           string clientScript;
           string windowAttribs;
           //Building Client side window attributes with width and height.//
           //Also the the window will be positioned to the middle of the screen//
           windowAttribs = "width=" + width + "px,"
  + "height=" + height + "px,"
  + "left=\'+((screen.width -"
  + width + ") / 2)+\',"
  + "top=\'+ (screen.height - "
  + height + ")/ 2+\'";

          //***Building the client script- window.open, with additional parameters***///
           clientScript = "window.open(\'" + PagePath + "\',\'"
 + windowName + "\',\'"
 + windowAttribs + "\');return false;";
           //regiter the script to the clientside click event of the 'opener' control*****///
           opener.Attributes.Add("onClick", clientScript);
       }
   }
}

How To Use This Method

1. Add Button controls in aspx page.

<asp:Button ID=”btn” runat=”server” Text=”Open Pop Up” />

2.Add Below code in Page_load of the aspx page.

Utilities.OpenPopUp(btn, “PoppEmail.aspx”, “EmailPro”, 700, 500);

This article has been posted at online dating site architect which providesfree online dating service and hosts Dating Idol Contests.

Aug 11

This article has been posted at online dating site architect which provides free online dating service and hosts Dating Idol Contests.

ICallback & JSON based Javascript Serialization Whilst working in asp.net sometimes we need to call server side methods asynchronously without have postback either it is full page postback or partial page postback so thanks to asp.net team to provide implementation of ICALLBACK very easily. ICALLBACK ICALLBACK is lightweight process, It uses well known xmlhttp object internally to call server side method, it doesn’t cause page postback so doesn’t cause page rendering so we to show output

ICallback & JSON based Javascript Serialization

Whilst working in asp.net sometimes we need to call server side methods asynchronously without have postback either it is full page postback or partial page postback so thanks to asp.net team to provide implementation of ICALLBACK very easily.

ICALLBACK

ICALLBACK is lightweight process, It uses well known xmlhttp object internally to call server side method, it doesn’t cause page postback so doesn’t cause page rendering so we to show output at client side we need to make output html ourselves and render controls manually.

ICALLBACKEVENTHANDLER

ICALLBACK implemented in asp.net by using ICALLBACKEVENTHANDLER interface has two methods, one of them used to be call from javascript (client side code) and other one return result asynchronously back to javascript function.

We just need to perform some action through server side code at server side and needs to return results but results could are in instance or object of any class which could be not easy for javascript code to handle easily so here we prefer JSON which stands for Javascript Object Notation.

JSON

JSON is lightweight data-interchange format. ASP.NET gives good support for JSON as well, it’s rapidly adopting because of its lightweight and easy to readable by human and machine as well.

CALLBACK SERVER SIDE CODE

Let’s first implement ICALLBACKEVENTHANDLER to call server side method asynchronously step by step J

Implement Server Side (C#) Page/Control class by System.Web.UI.ICallbackEventHandler

Following are definition of two methods which needs to implement:

RaiseCallbackEvent method invoke by thru javascript function

public void RaiseCallbackEvent(string eventArgument)

{

//to do code here

}

GetCallbackResult method invoke itself when processing of RaiseCallbackEvent method completed

public string GetCallbackResult()

{

return “”;

}

In Page_Load or Page_Init event

Following statements are used to register client side methods.

CallServer(arg, context) as name implies would use to call/raise server side method which was RaiseCallbackEvent string eventArgument)

ReceiveServerData(arg, context) would use to get result through arg parameter by GetCallbackResult()

protected void Page_Load(object sender, EventArgs e)

{

ClientScriptManager scriptMgr = Page.ClientScript;

String cbReference = scriptMgr.GetCallbackEventReference(this, “arg”, “ReceiveServerData”, “”);

String callbackScript = “function CallServer(arg, context) {” + cbReference + “; }”;

cm.RegisterClientScriptBlock(this.GetType(),“CallServer”, callbackScript, true);

}

CALLBACK CLIENT SIDE CODE

<script language=javascript type=text/javascript>

function ReceiveServerData(arg, context)

{

alert(arg);

}

function CallSrv()

{

CallServer(‘get customer’, );

}

script>

<input type=”button” value=”get customer” onclick=”CallSrv()” />>

Thants it. These are the steps which you need to use to call and get result from server side code using ICALLBACK.

Now we will go ahead for some very easy steps for JSON based javascript serialization to return results in javascript easily parseable format.

Suppose we have following class whose object we need to return to javascript function through javascriptserialization.

SAMPLE CLASS

public class Customer

{

public string Name;

public int Age;

}

JSON CODE

declare string jsonResult;

at class level, which would be use to contain final result and return.

After some sample code in both methods code will look like the following:

public void RaiseCallbackEvent(string eventArgument)

{

//populate Customer object to return

Customer customer = new Customer();

customer.Name = “Muhammad Adnan”;

customer.Age = 24;

//javascript serialization of Customer object

System.Web.Script.Serialization.JavaScriptSerializer jss;

jss = new System.Web.Script.Serialization.JavaScriptSerializer();

//stringbuilder to contain serialized customer object

System.Text.StringBuilder sbCustomer = new System.Text.StringBuilder();

jss.Serialize(customer, sbCustomer);

jsonResult = sbCustomer.ToString();

}

public string GetCallbackResult()

{

return jsonResult;

}

Asynchronously output would be within a millisecond and without Postback J

Conclusion:

Callback is lightweight technique used to call server side methods asynchronously from javascript without any postback and reloading/rendering of unnecessary parts of page and unnecessary code.

JSON is lightweight data interchange format to make server side class’ objects easily parse able by client side code to show output on browser.

Aug 11

How to convert an arraylist to dataset or datatable so that I can
filter or make a select distinct from it or Bind it to Gridview.

public DataSet ConvertArrayListToDataSet()
   {
       DataSet dsTemp = new DataSet();
       DataTable Tables = new DataTable();
       dsTemp.Tables.Add(Tables);

       dsTemp.Tables[0].Columns.Add("val", System.Type.GetType(
       "System.String"));

       foreach (string str in arraylistcontainer)
       {
           if (str != string.Empty)
           {
               DataRow myRow = dsTemp.Tables[0].NewRow();
               myRow[0] = str;
               dsTemp.Tables[0].Rows.Add(myRow);
           }

       }
   }

This article has been posted at online dating site architect which providesfree online dating service and hosts Dating Idol Contests.

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);
}
}

}

Aug 11

This article has been posted at online dating site architect which providesfree online dating service and hosts Dating Idol Contests.

how to derive your custom control from a base class and add your own features. In this article we’ll demonstrate how to derive a class from the BaseValidtor class to create your own validator control. Why would you do this? Well, in short the validator controls collection is very good, but as you will find they don’t cover every type of validation you will need to do. You can use the custom validtor control to accomidate this, but if you need to do validtation in multiple places within your web application or even multiple web applications and sites then this isn’t such a good solution. Instead, I would recommend creating a custom validation control and using that - why? Because it’s cleaner!
As previously mentioned this is an example of a very simple control. This validator control is derived from the base class BaseValidator . There is one properties added to the BaseValidator Email and the contents of the ControlToValidator must be this values.

EmailValidator.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

namespace EmailValidator
{
 public class EmailValidator : BaseValidator
 {
     protected string strEmail;

     public string Email
     {

         set
         {
             strEmail = value;
         }

     }

     protected override bool EvaluateIsValid()
     {
         string val = this.GetControlValidationValue(this.ControlToValidate);
         string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)
?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
         System.Text.RegularExpressions.Match match =
Regex.Match(val.Trim(), pattern, RegexOptions.IgnoreCase);
         if (match.Success)
         {

             return true;

         }
         else
         {

             return false;

         }

     }

 }
}
EvaluateIsValid
This method contains the code used to determine validity. The return value
is boolean. If false is returned then then the ControlToValidate will not
have a valid value; otherwise true.
GetControlValidationValue
This method gets the value associated with a specified INPUT control.
The return value is a string and it expects a parameter which should be the
ID of the INPUT control. You retrieve the INPUT controls ID property using the
following property

ControlToValidate
This property contains the ID property of the INPUT control the validation
control should validate.

How To Use
create a new application in VS.net and add the below code in aspx page.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="EmailValidator" Namespace="EmailValidator" TagPrefix="ccl" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
      <div>
          <asp:TextBox ID="txt" runat="server"></asp:TextBox>
          <ccl:EmailValidator ControlToValidate="txt" runat="server" ID="SS"
ErrorMessage="Envalid Email Address"
              Text="*">
          </ccl:EmailValidator>
          <asp:Button ID="btn" runat="server" Text="Submit" />
      </div>
  </form>
</body>
</html>
Aug 11
Trap window close event for IE browser
Let's say you want to trap the window close event for the web browser
so that you can give a confirmation dialog asking if the user is sure
to leave the page.The problem is that there is no onclose event for the
window object.The closest event might be onunload since it fires immediately
before the window object is unloaded. However, when the onunload event fires
it is too late to display a JavaScript alert. Therefore, we need an event that
fires prior to a page being  unloaded, which is onbeforeunload.
Define onbeforeunload event in your page <BODY> element as follows:

<BODY onbeforeunload="HandleOnClose()">

Then, add the following JavaScript code into the <HEAD> section of your
ASPX page:

<script language="javascript">

function HandleOnClose() {
   if (event.clientY < 0) {
      event.returnValue = 'Are you sure you want to leave the page?';
   }
}

</script>

The trick here is to check clientY property of the event object, which is used to
set or retrieve the y-coordinate of the mouse pointer's position relative to the
client area of the window, excluding window decorations and scroll bars. This way,
you can detect if the user clicked on X button to close the page, or clicked on
Refresh button to refresh the page, etc. This approach does not handle key events
such as Alt-F4 that lets the user close the window by using the keyboard.
You have to handle keyboard events separately

This article has been posted at online dating site architect which providesfree online dating service and hosts Dating Idol Contests.

Aug 11
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Please wait...We Are Processing Your Request..</title>

    <script>
        function PageOnLoad()
        {
            location.href = "<%=PageToLoad%>";
            document.images['imgsrc'].src="Images/Loading.gif";
        }
    </script>

</head>
<body bottommargin="0" leftmargin="0" rightmargin="0"
topmargin="0" onload="PageOnLoad();">
    <form id="form1" runat="server">
    <div>
        <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
            <tr>
                <td height="50" class="NormalText" align=center valign="bottom">
                <h3>We are processing your request. Please wait.. </h3>
                </td>
            </tr>
            <tr>
                <td align="center" height="250" valign="top">
            <img src="" name="imgsrc" /></td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Source Code of code-behind file (PageProcessor.aspx.cs)

protected string PageToLoad;

    protected void Page_Load(object sender, EventArgs e)
    {
        PageToLoad = Request.QueryString["PageId"];
    }

This article has been posted at online dating site architect providing free online dating service.

Aug 11
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Block F5 Key In IE & Mozilla</title>

<script language="JavaScript">

var version = navigator.appVersion;

function showKeyCode(e)
{
var keycode =(window.event) ? event.keyCode : e.keyCode;

if ((version.indexOf('MSIE') != -1))
{
if(keycode == 116)
{
event.keyCode = 0;
event.returnValue = false;
return false;
}
}
else
{
if(keycode == 116)
{
return false;
}
}
}

</script>

</head>
<body onload="JavaScript:document.body.focus();"
 onkeydown="return showKeyCode(event)">

</body>

</html>

This article has been posted at online dating site architect providing free online dating service.

Aug 11
<html>
<head>
</head>
<body>
<textarea id='clipText'>
Enter Text And Click Button To Copy Text To ClipBoard</textarea><br />
<input type=button id='bt'
onclick="clipboardData.setData('Text',document.getElementById('clipText').value);"
value="Copy" />
<input type=button
onclick="clipboardData.clearData('Text');" value="Clear" />
<input type=button
onclick="alert(clipboardData.getData('Text'));" value="Paste" />
</body>

This article has been posted at miami dating site architect providing free online dating service.

Aug 11
<html>
<head>
<script language="javascript">
function blockChar()
{
var str = document.getElementById('txt').value;
str = str.replace(/[^\d]*/g,'');
document.getElementById('txt').value = str;
}
</script>
</head>
<body onload="javascript:document.getElementById('txt').focus();">
<input type="text" id='txt' onkeyup="blockChar();" />
</body>
</html>

This article has been posted at miami dating site architect providing free online dating service.