Sunday, 25 February 2018

Exception Handling using ajax jquery client side script

 1.$.post(url, { model: dataModel ,weekending:weekending})
                   .done(function (data) {
                       if (data != "") {
                           $("#ConfictTimeSlip").val(data.ConfictTimeSlip);
                           if (data.ConfictTimeSlip > 0) {
                               $("#lblPopupmessage").html("The hours you have entered above conflict with a time slip that already exists in the our system.<br/>Duplicate time slips are not allowed!").css('color', 'red');
                               $('#btnCorrect').prop('disabled', true);
                           }
                           else{$('#btnCorrect').prop('disabled', false);}
                       }
                   })
                .fail(handleAjaxError)



2.$.ajax({
                        type: "GET",
                        url: url,
                        success: function (data) { $("#tblBindPersonalJobBank").html(data); },
                        error: handleAjaxError
                    });

Example of Table variable in Sql Server

1.Creating Table Variable:

DECLARE @Posted_Split TABLE (
Post_Site INT
,Post_Type TINYINT
)

2.Inserting data into Table Variable:

INSERT INTO @Posted_Split
select 2,0

3.To view data of Table Variable:

select Post_Site,Post_Type from @Posted_Split


4.Joining with Table Variable:

UPDATE tblJobPostData set JobPost_ID=450,Post_Type=PS.Post_Type,Post_Site=PS.Post_Site,IsProcessed=0
from tblJobPostData JP inner join @Posted_Split PS on PS.Post_Type=JP.Post_Type and PS.Post_Site=JP.Post_Site
where JP.jobpost_id=450

CTE example in SQL Server_To get Previous n Next value

WITH CTE AS (
SELECT
rownum = ROW_NUMBER() OVER (ORDER BY p.jobpost_id),
p.jobpost_id
FROM tblJobPostDetails p
)
SELECT
prev.jobpost_id PreviousValue,
CTE.jobpost_id,
nex.jobpost_id NextValue
FROM CTE
LEFT JOIN CTE prev ON prev.rownum = CTE.rownum - 1
LEFT JOIN CTE nex ON nex.rownum = CTE.rownum + 1

How to call client side function from Server side or vice versa in VB.Net

1st option

ClientScript.RegisterClientScriptBlock(Page, typeof"Validate(ID), true);

OR

<asp:Button OnClientClick = "Validate(ID)"/>

Use this on page load:

RegisterStartupScript("Unique key", "Validate(ID);");

2nd option

protected void MyButton_Click(object sender, EventArgs e)
{
    Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "AnotherFunction();", true);
}



Interview question:5 anchor tag and 5 span tag. on click of anchor tag show only that respective span tag others should not show.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>


$(document).ready(function(){
$(".item span").hide();

$(".item a").click(function(e){
e.preventDefault();
var $this=$(this).parent().find("span");
$(".item span").not($this).hide();
$this.toggle();

});


});
</script>
</head>
<body>

<div class="item"><a href="#">aaa1</a><span>ppp1</span></div>
<div class="item"><a href="#">aaa2</a><span>ppp2</span></div>
<div class="item"><a href="#">aaa3</a><span>ppp3</span></div>
<div class="item"><a href="#">aaa4</a><span>ppp4</span></div>
<div class="item"><a href="#">aaa5</a><span>ppp5</span></div>


</body>
</html>

Interview question: what is the out put of below question?

<script>

var x = 5;
var y = 'a';
var e = 6;
var z = x + y+e;
document.getElementById("demo").innerHTML =
"The value of z is: " + z;

</script>

Output:The value of z is: 5a6

Check string is Palindrome or not using Console Application in C#

static void Main(string[] args)
        {
            Console.WriteLine("Enter a string to check Pallindrom.");
            string str=Console.ReadLine();
            string strRev = "";
            for (int i = str.Length - 1; i >= 0; i--)
            {
                strRev += str[i];
            }
            if (str.ToUpper() == strRev.ToUpper())
            {
                Console.WriteLine("its a Pallidrom.");
                Console.ReadLine();
            }else
            {
                Console.WriteLine("its not a Pallidrom.");
                Console.ReadLine();
            }
        }