Sunday, October 31, 2010

How to show client side message from Server Side Code?

File to be uploaded can't be more than 4 MB.

Protected Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error
        Dim ex As Exception
        ex = Server.GetLastError
        If TypeOf (ex) Is HttpException Then
            If ex.ToString.IndexOf("System.Web.HttpException: Maximum request length exceeded") > -1 Then
                Server.ClearError()
                Dim str As String = "<script type=""text/javascript""></script>"
                Dim sb As StringBuilder = New StringBuilder()
                sb.Append("<script>")
                sb.Append("alert(""Nothing DONE!!!\nUploaded File size should not exceed 4 MB. Please Delete Selected File.\nERROR: " + ex.Message + """);window.history.back();")
                sb.Append("</scri")
                sb.Append("pt>")
                Dim s As String = sb.ToString
                Page.RegisterStartupScript("test", sb.ToString())
            End If
        End If
    End Sub

Wednesday, October 27, 2010

Thread Safety Example

Thread Safety

It's new in .Net 2.0.
It's used to prevent DeadLock.
Thread Safety is a technique that allows us cross thread operation in a safe manor.
Important properties:
→ CheckForIllegalThreadCalls: It's bydefault True. Gets or Sets a value indicating whether to calls on the wrong thread that access a control's System.Windows.Forms.Control.Handle Property when an application is being debugged.
→ InvokeRequire(T, F): it is a property of Control. Default value is true. It means control is in different domain and calling is being done from different domain.

drag and drop two textbox and a button on the page.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Test_Thread1
{
public partial class Form1 : Form
{
ThreadStart ts1,ts2;
Thread th1,th2;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
ts1 = new ThreadStart(abc);
th1 = new Thread(ts1);
th1.Start();
ts2 = new ThreadStart(xyz);
th2 = new Thread(ts2);
th2.Start();
}
private void abc()
{
for (int i = 0; i < 20; i++)
{
mno(textBox1, "IndiaMART InterMESH LTD.");
}
}

private void xyz()
{
for (int i = 0; i < 20; i++)
{
mno(textBox2, "IndiaMART InterMESH LTD New");
}
}

private delegate void MyDelegate(TextBox t1, string S);
private void mno(TextBox t1, string S)
{
if (t1.InvokeRequired)
{
MyDelegate dd = new MyDelegate(mno);
t1.Invoke(dd, t1, S);
}
else
{
t1.Text += Environment.NewLine + S;
}
}
}
}

Thursday, October 7, 2010

How to trim string in javascript?

<script language="JavaScript" type="text/javascript">
<!--
        String.prototype.trim = function() {
            return this.replace(/^\s*/, "").replace(/\s*$/, "");
        }

        var s = new String(" Hello ");
        // use it like this
        s = s.trim();
        alert("!" + s + "!");

// end hiding contents -->
</script>

Friday, October 1, 2010

how to move the title text of tabs in browser

add following code in head of source
<script language="javascript" type="text/javascript">
   var rev = "fwd";
    function titlebar(val) {
        var msg = 'Welcome Naween';
        var res = " ";
        var speed = 100;
        var pos = val;

        //msg = "   |--- " + msg + " ---|";
        var le = msg.length;
        if (rev == "fwd") {
            if (pos < le) {
                pos = pos + 1;
                document.title = msg.substring(0, pos);
                timer = window.setTimeout("titlebar(" + pos + ")", speed);
            }
            else {
                rev = "bwd";
                timer = window.setTimeout("titlebar(" + pos + ")", speed);
            }
        }
        else {
            if (pos > 0) {
                pos = pos - 1;
                var ale = le - pos;
                document.title = msg.substring(ale, le);
                timer = window.setTimeout("titlebar(" + pos + ")", speed);
            }
            else {
                rev = "fwd";
                timer = window.setTimeout("titlebar(" + pos + ")", speed);
            }
        }
    }

    titlebar(0);
</script>

how to add icon at start of link in status bar of Website

Design a logo of logo with the extension .ico
Design the gif of size 32*32 or 16*16
At following code under the head tag at html page
suppose we have a abc.ico and a xyz.gif
<link rel="shortcut icon" href="../abc.ico" >
    <link rel="icon" type="image/gif" href="..xyz.gif">