Pages

Thursday, January 20, 2011

Call server side function on Function key press

<script type="text/javascript">
document.onkeyup = KeyCheck;
function KeyCheck(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode; switch (KeyID) {
        case 118:
            __doPostBack('__Page', 'F7');
            break;       
        case 39:
            //__doPostBack('__Page', 'ArrowRight');
            __doPostBack('Button2', '')
            break;
        case 40:
            __doPostBack('__Page', 'ArrowDown'); break;
    }
}
</script>

<form id="form1" runat="server">
     <a id="LButton3" href="javascript:__doPostBack('Button2','')">LinkButton</a>
     <a id="A1" href="DisableBackButton.aspx">LinkButton</a>
     <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />   
</form>
Server Side Code
protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(DateTime.Now.ToString());
        Page.ClientScript.GetPostBackEventReference(this, "");
        string eventArgs = Request["__EVENTARGUMENT"]; if (!string.IsNullOrEmpty(eventArgs))
        {
            switch (eventArgs)
            {
                case "F7":
                    a("F7");
                    break; 
            }
        }
    }
public void a(string s)
    {
        Response.Write(s);
    }

Tuesday, January 18, 2011

Get Multiple Rows data in a single column

DECLARE @list varchar(8000)
SELECT @list=Cast(MEMBERID as varchar(50))+'-'+MEMBERNAME + ',' + COALESCE(@list,'')
FROM MemberDetail
SELECT LEFT(@list,LEN(@list)-1)

Get IP address from URL

using System.Net;
string howtogeek = Request.Url.Host;
IPAddress[] addresslist = Dns.GetHostAddresses(howtogeek);
string hostname = addresslist[0].ToString();

Saturday, January 15, 2011

UploadModule is not installed into web.config.! using

Please check your IIS mode then change the web.config.

IIS 6.0 and IIS 7.0 Classic mode

<configuration>
  <system.web>
    <httpModules>
      <add name="CuteWebUI.UploadModule" type="CuteWebUI.UploadModule,CuteWebUI.AjaxUploader"/>
     </httpModules>
  </system.web>
</configuration>

IIS 7.0 Integrated mode
<configuration>
  <system.webServer>
    <modules>
      <add name="CuteWebUI.UploadModule" type="CuteWebUI.UploadModule,CuteWebUI.AjaxUploader"/>
    </modules>
  </system.webServer>
</configuration>

Tuesday, January 4, 2011

Create Capcha using Javascript

<script language="javascript">
        function show() {
             var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
                var string_length = 5;
                var randomstring = '';
                for (var i=0; i<string_length; i++)
                {
                    var rnum = Math.floor(Math.random() * chars.length);
                    randomstring += chars.substring(rnum,rnum+1);
                }   
                var main = document.getElementById('txt1');
                main.value = randomstring;
        }
    </script>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="text" id="txt1" runat="server" style="border-style: none; border-color: inherit;
            border-width: medium; background-color: black; color: red; font-family: 'Curlz MT';
            font-size: x-large; font-weight: bold; font-variant: normal; letter-spacing: 10pt;
            width: 120px;" value="1AsD" />
        <input type="button" onclick="show()" value="Change" />
    </div>
    <asp:TextBox ID="txtverification" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" Text="Verification" OnClick="Button1_Click" />
    &nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
    </form>
</body>
Code Behind write:
protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtverification.Text == txt1.Value)
        {
            lblmsg.Text = "Successfull";
        }
        else
        {
            lblmsg.Text = "Failure";
        }
    }

Dopostback on Key Press using javascript

<script type="text/javascript">
document.onkeyup = KeyCheck;
function KeyCheck(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode; 
//alert("KeyId="+KeyID);
switch (KeyID) {
        case 118:
            __doPostBack('__Page', 'F7');
            break;
        case 119:
            __doPostBack('__Page', 'F8');
            break;
        case 120:
            __doPostBack('__Page', 'F9');
            break;
        case 121:
            __doPostBack('__Page', 'F10');
            break;
    }
}
</script>
Code Behind write:
protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.GetPostBackEventReference(this, "");
        string eventArgs = Request["__EVENTARGUMENT"]; if (!string.IsNullOrEmpty(eventArgs))
        {
            switch (eventArgs)
            {
                case "F7":
                    a("F7");
                    break;
                case "F8":
                    a("F8");
                    break;
                case "F9":
                    a("F9");
                    break;
                case "F10":
                    a("F10");
                    break;
            }
        }
    }
   public void a(string str)
    {
         Response.Write("You pressed : " + str);
    }

Monday, January 3, 2011

Delete duplicate rows from the table

Create table ##Test (a int not null, b int not null, c int not null, id int not null identity) on [Primary]
GO
INSERT INTO ##Test (A,B,C) VALUES (1,1,1)
INSERT INTO ##Test (A,B,C) VALUES (1,1,1)
INSERT INTO ##Test (A,B,C) VALUES (1,1,1)

INSERT INTO ##Test (A,B,C) VALUES (1,2,3)
INSERT INTO ##Test (A,B,C) VALUES (1,2,3)
INSERT INTO ##Test (A,B,C) VALUES (1,2,3)

INSERT INTO ##Test (A,B,C) VALUES (4,5,6)
GO
Select * from ##Test
GO
Delete from ##Test where id <
(Select Max(id) from ##Test t where ##Test.a = t.a and
##Test.b = t.b and
##Test.c = t.c)
GO
Select * from ##Test
drop table ##Test
GO