Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack


Hi
I was facing error like
“Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack “.

when i had written code like this

Response.Redirect(url);

To solve this error, i made like this.

Response.Redirect(url,false);

How to make enable/disable particular row cell of Gridview ?



Hi
In our daily coding, so many time we have to do particular action in some particular cell. For example we have to do enable/disable some row cell of Gridview on some condition. Then we can do like this
Step1: Click on onrowdatabound event of Grid
Step2: Write the code in code behind like this

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

Button btn1 = (Button)e.Row.FindControl(“BtnSubmit”);

if (e.Row.RowType == DataControlRowType.DataRow)
{

Label LblEmpSal = (Label)e.Row.FindControl(“lblEmpSal”);
if (LblEmpSal.Text == “15000”)
{
btn1.Enabled = false;
}

}

}

How to call the webservice using Ajax on client side?


Hi
I hope that you are knowing the basic concept of web service.
There are so many method to call the web service.
1.Using Ajax (script manager control) and JavaScript
2.using Jquery.
3.Using C# code.

Here i m going to show you using script manager and Javascript.
Step1. Create the simple webservice like this, and UnComment this line
[System.Web.Script.Services.ScriptService]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

///
/// Summary description for WebService
///
[WebService(Namespace = “http://tempuri.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

public WebService ()

{

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return “Hello World”;
}

}

Step2: Write the Javascript code in default page like this

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head runat=”server”>
<title></title>
<script language=”javascript” type=”text/javascript”>
function onClick()

{

WebService.HelloWorld(OnComplete, OnTimeOut, onerror);

return true;
}
function OnComplete(args) {
document.getElementById(‘Label1’).innerHTML = args;
}
function OnTimeOut(args) {
alert(“Service call timed out.”);
}

function OnError(args)

{
alert(“Error calling service method.”);
}
</script>
</head>

<body>

<form id=”form1″ runat=”server”>
<div>
<asp:ScriptManager ID=”ScriptManager1″ runat=”server” >
<Services>
<asp:ServiceReference Path=”WebService.asmx” />
</Services>
</asp:ScriptManager>
<input id=”Button1″ type=”button”
value=”button” onclick=”return onClick();” />
<br />
<br />
<label id=”Label1″ style=”width: 318px”></label>

</div>
</form>
</body>
</html>

How to display jquery animated confirmation message in asp.net?


Hi
While working in one of my personal project, I used “displaying confirmation message using jquery”. It is very nice and easy to use.
Step1: Download the related jquery plugin and Write the HTML code like this

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
<title>Add New Customer</title>
<link href="Default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server" defaultbutton="Save" defaultfocus="Name">
<asp:ScriptManager runat="server">
<Scripts>
<asp:ScriptReference Path="~/jquery-1.2.6.min.js" />
<asp:ScriptReference Path="~/jquery.blockUI.js" />
<asp:ScriptReference Path="~/Default.js" />
</Scripts>
</asp:ScriptManager>

<div id="EntryForm">
<label for="Name">Name:</label>
<asp:TextBox runat="server" ID="Name" />

<label for="Address">Address:</label>
<asp:TextBox runat="server" ID="Address" />

<label for="City">City:</label>
<asp:TextBox runat="server" ID="City" />

<label for="State">State:</label>
<asp:TextBox runat="server" ID="State" />

<label for="Zip">Zip:</label>
<asp:TextBox runat="server" ID="Zip" />

<asp:Button runat="server" ID="Save" OnClick="Save_Click"
Text="Add Customer" UseSubmitBehavior="false" />
</div>

<asp:UpdatePanel runat="server" ID="upConfirmation">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Save" />
</Triggers>
<ContentTemplate>
<asp:Panel runat="server" ID="ConfirmSave" Visible="false">
<h3><asp:Literal runat="server" ID="CustomerName" /> added</h3>

<a href="#" id="CloseConfirm">Close</a>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

Step2:Write the code in code behind like this

using System;
using System.Web.UI;

public partial class _Default : System.Web.UI.Page
{
protected void Save_Click(object sender, EventArgs e)
{
// Save the customer to your data store here.
System.Threading.Thread.Sleep(2000);

// Display the confirmation.
ConfirmSave.Visible = true;

// You can custamize the confirmation.
CustomerName.Text = Name.Text;
}
}

How to include caching in WebService ?


Hi
If our requirement is to fetch the same data again and again from database, then we can use caching concept in web service to increasing the performance and avoid the unnecessary hit to database.
Syntax for Caching in web service
[WebMethod(CacheDuration = 5)]
Where 5 is time duration in second.

Complete Syntax is like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

///
/// Summary description for TestCaching
///

[WebService(Namespace = “http://tempuri.org/&#8221;)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class TestCaching : System.Web.Services.WebService {

//This syntax is used for cache in webservice
[WebMethod(CacheDuration = 5)]
public string GetServiceTime()
{
return DateTime.Now.ToString();
}

}