Wednesday, 21 November 2012

How to Place Span Inside Text Input Field



First Create a text box and Span.

Then you have to write a style for span.

In Position absolute property is important for placed the text inside the text box.

Based on our text box, we need to change the left and top property for the span.

For Example,

<input type="text" style="height:30px; width:300px;" >

<span style="position:absolute; left:285px;top:56px;color:#999999;">Test</span>

 

Thursday, 4 October 2012

Split Function in Sql Server

We can write function in Sql Server,



CREATE FUNCTION Split
(
    @String nvarchar(4000),
    @Delimiter char(1)
)   
RETURNS
    @Results TABLE (Items nvarchar(4000))   
AS
    BEGIN   
    DECLARE @INDEX INT   
    DECLARE @SLICE nvarchar(600)   
    -- HAVE TO SET TO 1 SO IT DOESNT EQUAL Z   
    --     ERO FIRST TIME IN LOOP   
    SELECT @INDEX = 1   
    -- following line added 10/06/04 as null   
    --      values cause issues   
    IF @String IS NULL RETURN   
    WHILE @INDEX !=0    
        BEGIN    
         -- GET THE INDEX OF THE FIRST OCCURENCE OF THE SPLIT CHARACTER   
         SELECT @INDEX = CHARINDEX(@Delimiter,@STRING)   
         -- NOW PUSH EVERYTHING TO THE LEFT OF IT INTO THE SLICE VARIABLE   
         IF @INDEX !=0   
          SELECT @SLICE = LEFT(@STRING,@INDEX - 1)   
         ELSE   
          SELECT @SLICE = @STRING   
         -- PUT THE ITEM INTO THE RESULTS SET   
         INSERT INTO @Results(Items) VALUES(@SLICE)   
         -- CHOP THE ITEM REMOVED OFF THE MAIN STRING   
         SELECT @STRING = RIGHT(@STRING,LEN(@STRING) - @INDEX)   
         -- BREAK OUT IF WE ARE DONE   
         IF LEN(@STRING) = 0 BREAK   
    END   
    RETURN   
END


Then We can call that function from our stored procedure like,


Declare @input varchar(255)
Set @input = 'EMP101,EMP155,EMP199'


 --create table #Temp1 (sno int identity(1,1), empno varchar(100)) 
select ID= IDENTITY(int, 1,1),* into #Temp from dbo.Split(@input,',')
select * from #Temp
drop table #Temp 
 

Wednesday, 5 September 2012

ASP.Net Links

Get the current page name using JavaScript

 Differences Between WCF and ASP.NET Web Services

JavaScript Event Calendar | Ajax Scheduler

.Net Connector


Get Started With JSON
http://www.webmonkey.com/2010/02/get_started_with_json/ 



jQuery Mobile Events Diagram



Creating Printer Friendly Pages


Hashtables vs. Arrays


Advanced Random Numbers in JS


Random Colors in JavaScript


Finding an Element's X, Y Position


Shuffling an Array in JavaScript


online photoshop


Learn how to remove duplicate values from an array in #JavaScript

http://t.co/h2D5Fk0q
 

Friday, 3 August 2012

ASP.Net Listbox with Checkbox - Get and Set Selected Value

I would recommend using a div styled like a listbox then we can have whatever we want in there.

<div style="width:200px; height:150px; padding:2px; overflow:auto; border: 1px solid #ccc;">
    <asp:CheckBoxList class="BodyTxt" ID="ChkServicestopitch" runat="server">
          <asp:ListItem Text="ERP" Value="1"></asp:ListItem>
          <asp:ListItem Text="CRM" Value="2"></asp:ListItem>
          <asp:ListItem Text="E-Commerce" Value="3"></asp:ListItem>
          <asp:ListItem Text="Business Intelligence" Value="4"></asp:ListItem>
          <asp:ListItem Text="HRMS" Value="5"></asp:ListItem>
          <asp:ListItem Text="Mobile Application" Value="6"></asp:ListItem>
          <asp:ListItem Text="Web Application" Value="7"></asp:ListItem>         
    </asp:CheckBoxList>
 </div>

The div containing the checkbox is shown as follows,

 
 











Getting the selected value and text from checkbox list,

string strText = "";
string strValue = "";
//GET THE SELECTED VALUE FROM CHECKBOX LIST
for (int i = 0; i < ChkServicestopitch.Items.Count; i++)
{
if (ChkServicestopitch.Items[i].Selected)
      {
            if (strText.Length == 0)
            {
                  strText = ChkServicestopitch.Items[i].Text;
                  strValue = ChkServicestopitch.Items[i].Value;       
            }
            else
            {
                  strText += "," + ChkServicestopitch.Items[i].Text;
                  strValue += "," + ChkServicestopitch.Items[i].Value;
            }
       }
}
lblResult.Text = "Checkbox Selected Text : " + strText + "</br> Checkbox Selected Value : " + strValue;

Output :


Set the selected value in Checkbox list based on passing the value,

//SET THE SELECTED VALUE IN CHECKBOX
string strValue = "1,3,4,5";
string[] splitStrValue = strValue.Split(',');
for (int i = 0; i < splitStrValue.Length; i++)
{
for (int j = 0; j < ChkServicestopitch.Items.Count; j++)
{
if (splitStrValue[i].ToString() == ChkServicestopitch.Items[j].Value.ToString())
{
ChkServicestopitch.Items[j].Selected = true;
}
}
}

Here i would pass the value as 1,3,4,5.

Output : 













Clear the selected checkbox value,

for (int j = 0; j < ChkServicestopitch.Items.Count; j++)
{
ChkServicestopitch.Items[j].Selected = false;
}
 


 

Disable back button in Browser Using Javascript

Declare a script:

<script>
    function noBack() { window.history.forward(); }
</script>

Inside the body add the below lines like below

<body onload="noBack();" onpageshow="if(event.persisted)noBack();" onunload="">

Output for Firefox and IE are as follows,


 

Wednesday, 1 August 2012

Difference between OnBlur and OnChange in Javascript

onblur fires when a field loses focus, while onchange fires when that field's value changes.
These events will not always occur in the same order, however.

In Firefox, tabbing out of a changed field will fire onchange then onblur, and it will normally do the same in IE.

However, if you press the enter key instead of tab, in Firefox it will fire onblur then onchange, while IE will usually fire in the original order.

However, I've seen cases where IE will also fire blur first, so be careful.
You can't assume that either the onblur or the onchange will happen before the other one.

For eg,

I have created the textbox in aspx page and called these two events like onblur and onchange from my code behind file as follows,

In .aspx page,
        <asp:TextBox ID="txtTest" runat="server"></asp:TextBox>   

From Code behind file,
     protected void Page_Load(object sender, EventArgs e)
    {       
        txtTest.Attributes.Add("onblur", "fnTestOnBlur();");
        txtTest.Attributes.Add("onchange", "fnTestOnChange();");

    }

Javascript function,
       <script type="text/javascript" language="javascript">
        function fnTestOnBlur() {
            alert("Inside OnBlur");
        }

        function fnTestOnChange() {
            alert("Inside OnChange");
        }       
    </script>


Wednesday, 2 May 2012

Getting Device IMEI From Android to Phonegap

In Android :
************
import android.content.Context;
import android.telephony.TelephonyManager;

String IMEI;
int Phno;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
IMEI  = telephonyManager.getDeviceId();
Phno =  telephonyManager.getPhoneType();
super.loadUrl("file:///android_asset/www/index.html?IMEI="+IMEI+"&Phno="+Phno);

In Phonegap :
**************
var query = location.href.substring((location.href.indexOf('?')+1), location.href.length);
if(location.href.indexOf('?') < 0) query = '';
    querysplit = query.split('&');
    query = new Array();
for(var i = 0; i < querysplit.length; i++)
{
        var namevalue = querysplit[i].split('=');
        namevalue[1] = namevalue[1].replace(/\+/g, ' ');
        query[namevalue[0]] = unescape(namevalue[1]);
}

var DeviceIMEI = query['IMEI'];
alert("DeviceIMEI : " + DeviceIMEI);

Thursday, 26 April 2012

Alert Dialog - Android

        AlertDialog.Builder adb = new AlertDialog.Builder(context);
        adb.setTitle("Fastrack Car Availability");
        adb.setMessage("100 Cars Available Currently");
        adb.setPositiveButton("Ok", new DialogInterface.OnClickListener()
        {
        public void onClick(DialogInterface dialog, int id)
        {   
            // Action for 'Ok' Button
            setContentView(R.layout.bookatrip1);   
           
        }
        });
        adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
            // Action for 'Cancel' Button
            dialog.cancel();
            }
        });
        adb.setIcon(R.drawable.bookatrip1);
        adb.show();