Thursday, September 30, 2010

Google Map in Asp.Net

Introduction

In this article, We are going to Implement Google Map using Asp.net Custom control. It Offers extremely easy and fast way of adding Google Maps API support on your ASP.NET pages.

Lets go through this application step by step

Step 1:

Create a new website >select the programming language as c#> Name the project as GoogleMap

Step 2:

Now lets go to this site and download the DLL from the Recommended download

http://googlemap.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=26521

Step 3:

Now i think that you people have download that ddl.. Now right click on to the website and add reference to arthem.GoogleMap.

Step 4:

Now add this in the Web.config under Pages tag and under Controls.


Step 5:

Now go to this site and give your URL in click on Generate API Key.

http://code.google.com/apis/maps/signup.html

Copy this Key and paste in some document..

Step 6:

Now add this lines of lines of code in .aspx page


We are using Google Marker to indicate your location. Zoom can be set until 9.


Step 7:

Now Lets run this application.. Output will be displayed like this



Download Complete Code

When JavaScript Disabled then redirect noscript page

In this article I have provided some trick for not allowing user to aceess your site when javascript is disabled in browser. It’s very simple and can be implemented with Html tags <META> and <noscript>. Just like script there is <noscript> tag. This tag runs when there is no script enabled for the browser.

<h6> Step1</h6>

create a page where you want to redirect user when JavaScript is disabled. Say we created a page "noscript.aspx". See below code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
document.location.href = "Login.aspx";
</script>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<div style="text-align: center; color: Red; font-family: Calibri; font-size: 12pt; width:400px">
<b>* JavaScript Need To Be Enabled To visit Requested page.</b>
</div>
</div>
</form>
</body>
</html>

User will land on this page when any page is requested with disabled javascript. Specify , on which page you want to redirect user when javascript is enabled in "script>" tag.

<h6>Step2</h6>

In main master page of your site write <noscript> tag.Specify URL = noscript.aspx page we have created.Meta tag will redirect user to given URL (noscript page in this case) when javascript is disabled.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<noscript>
<meta http-equiv="refresh" content="0;URL=noscript.aspx" />
</noscript>
</body>
</html>

Run the application and test it. :)

Wednesday, September 29, 2010

The Repeater control is a data-bound control. It uses templates to display data. It lacks the built-in support for paging, editing and sorting. The Repeater control may be bound to a database table, and an XML file. In this control, the content and layout of list items is defined using Templates. Every Repeater must define an ItemTemplate.
Templates:
There are 5 templates available for a Repeater:
1. Header Template2. ItemTemplate3. AlternatingItemTemplate4. SeparatorTemplate
5. FooterTemplateLet me discuss these templates in details:

HeaderTemplate: It is used to specify an optional header row. It is used to determine the content and layout of the list header.
ItemTemplate :It is used to define the content and layout of items within the list.AlternatingItemTemplate: This template is used for elements that are rendered every second row of data. This allows you to alternate background colors.
SeparatorTemplate: The SeparatorTemplate is rendered between each row.FooterTemplate: It is used to specify an optional footer row. It is used to determine the content and layout of the list footer.
All these 5 templates will be placed within the Repeater .
HeaderTemplateItemTemplate

AlternatingItemTemplate

FooterTemplate

SeperatorTemplate
Link Buttons:

These link Button placed outside of the repeator control



Pagination in Repeater:

Repeater doesn’t support Paging directly. But we can implement Paging in Repeater by using PagedDataSource.

PagedDataSource:
This class comes from the System.Data.Web.UI.WebControls namespace, so we need not import any additional namespace to the page.

This class encapsulates the paging related properties of a data-bound control.
Few properties of PagedDataSource class are as follows:

1. PageSize - This property defines how many records are displayed on a page and it takes an integer (by default it's set at 10).
2. AllowPaging - This property determines whether the paging should be turned on or off (Boolean "true" or "false"). By default it is set to "false".
3. CurrentPageIndex - This gets/sets the current page number. By default it returns 0.
4. PageCount - Returns the total number of pages that are available.
5. DataSource - The value of this property will be the source of the data which we want to page.
6. IsFirstPage - Returns "true" or "false". It depends on whether the current page is the first page in the series.
7. IsLastPage -- Returns "true" or "false". It depends on whether the current page is the last page in the series.

Connection Object and Property Decleration follows:


Code for Page_Load Event


Code written in BringData() method


Here I have created an instance of the PagedDataSource class. In the next line, I had set the DataSource In the following line the AllowPaging property is to "true". And on the next line the PageSize property is set to 3.


Contents of the Table tblUser


Output
The output is as follows:


Conclusion
This is all about Repeater Control. Hope u all enjoy reading it. Please provide me feedback on it, if any improvements required.

Paging with Repeater Control

The Repeater control is a data-bound control. It uses templates to display data. It lacks the built-in support for paging, editing and sorting. The Repeater control may be bound to a database table, and an XML file. In this control, the content and layout of list items is defined using Templates. Every Repeater must define an ItemTemplate.
Templates:
There are 5 templates available for a Repeater:
1. Header Template2. ItemTemplate3. AlternatingItemTemplate4. SeparatorTemplate
5. FooterTemplateLet me discuss these templates in details:

HeaderTemplate: It is used to specify an optional header row. It is used to determine the content and layout of the list header.
ItemTemplate :It is used to define the content and layout of items within the list.AlternatingItemTemplate: This template is used for elements that are rendered every second row of data. This allows you to alternate background colors.
SeparatorTemplate: The SeparatorTemplate is rendered between each row.FooterTemplate: It is used to specify an optional footer row. It is used to determine the content and layout of the list footer.
All these 5 templates will be placed within the Repeater .
HeaderTemplateItemTemplate

AlternatingItemTemplate

FooterTemplate

SeperatorTemplate
Link Buttons:

These link Button placed outside of the repeator control

Add Image

Pagination in Repeater:

Repeater doesn’t support Paging directly. But we can implement Paging in Repeater by using PagedDataSource.
PagedDataSource

This class comes from the System.Data.Web.UI.WebControls namespace, so we need not import any additional namespace to the page.



This class encapsulates the paging related properties of a data-bound control.
Few properties of PagedDataSource class are as follows:

1. PageSize - This property defines how many records are displayed on a page and it takes an integer (by default it's set at 10).
2. AllowPaging - This property determines whether the paging should be turned on or off (Boolean "true" or "false"). By default it is set to "false".
3. CurrentPageIndex - This gets/sets the current page number. By default it returns 0.
4. PageCount - Returns the total number of pages that are available.
5. DataSource - The value of this property will be the source of the data which we want to page.
6. IsFirstPage - Returns "true" or "false". It depends on whether the current page is the first page in the series.
7. IsLastPage -- Returns "true" or "false". It depends on whether the current page is the last page in the series.

Connection Object and Property Decleration follows:

Tuesday, September 28, 2010

AJAX DLL

AIM : An Ajax DLL is used to call server side method asynchronously without processing the whole page life cycle.

Introduction

Ajax DLL is a library developed using .NET 2005 for ASP.NET 2.0/3.0/3.5. It is used to call Server side methods from JavaScript. You can pass the method parameter value from JavaScript. A parameter can be a variable or an object.

In the given example, I have used the parameter as a string variable, an array object and a class object. A drawback of this dll is that you cannot access your server control in your method, because Page Life Cycle is not involved during the method call. But you can access your server control from javascript and assign the value which will be returned by Ajax method.
Using the Code

it’s very simple to use Ajax dll. You need to create a web application or a web site and add reference of Ajax.dll which is in the attached file.

Once a DLL has been added into your application, you need to place a one line code on Page_Load event as below :

This line will register your page class in DLL with all your AJAX method[s] written in the page class, which are given in the image below. Check the below image, you will find that the methods have been annotated with an attribute Ajax.AjaxMethod. You need to annotate with an attribute to the methods which you want to call from javascript.




There are 5 optional parameters with the Ajax.AjaxMethod attribute :

  1. Method Name: A method which you want to call from JS. Default will be the same method name which you have created.
  2. Js Callback method name: On Successful End Request of the Ajax call. Default will be the Callback_.
  3. Js Error method Name: any Error at the time of End Request of the Ajax call. Default will be the Error_.
  4. Loading Text flag: Bool flag to show a loading text or not. Default value is false.
  5. Loading Text: Which text you want to show. Default Text is string.Empty.

















Once the methods have been written, you can call all these methods from JS as defined in the first parameter of Ajax.AjaxMethod. For that, you can write JS methods as below:









Check here the CallTest1

() function, from the function Test1 method is called as defined in the first parameter of Ajax attribute. The parameter value and the method name should be the same.

At last, you need to apply some configuration in the web.config file as below:







Also you need to add the extension .ajax and .ajaxj in your directory setting with ASP.NET API. Find the steps below for that

1. Open the IIS.
2. Open a property window of your virtual directory.
3. Click on "Configuration" button to open "Application Configuration" window under "Virtual Directory" tab
4. Under Mapping tab, click on "Add" button, it will open "Add/Edit Application Extension Mapping" window.
5. Write the extension ".ajax" in Extension textbox.
6. Click on "Browse" button, the default directory will be Framework Version directory. if it is not then select your framework version directory. it will be at "C:\WINDOWS\Microsoft.NET\Framework\vx.x.xxxxx".
7. Select "aspnet_isapi.dll" from that directory" and click on "Open" button of dialog box.
8. In Verbs frame select "Limit to" radio button and write "POST" in the textbox.
9. Uncheck the "Check that file exists" checkbox.
10. Click on "OK".
11. Same steps need to follow to add ".ajax" extension but in verb frame write "GET" in place of "POST" for that.

=====================
Source Code is below

For Front End default.aspx

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="DemoAjaxApp._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ajax Demo</title>

<script language="javascript" type="text/javascript">

function CallTest()
{
var id=document.getElementById('txtClientId').value;
Test(id);
}

function NameLength(obj)
{
var i=0;
var newdiv = document.getElementById('EmpData');
newdiv.innerHTML = "";
if(obj == null)
{
newdiv.innerHTML = "No Employee Found";
return;
}
mytable = document.createElement("table");
mytable.cellSpacing = "0px";
mytable.style.border = "1px solid #000";
mytablebody = document.createElement("tbody");
mycurrent_row = document.createElement("tr");
for(i=0;i<obj.Rows[0].Columns.length;i++)
{
mycurrent_cell = document.createElement("td");
currenttext = document.createTextNode(obj.Rows[0].Columns[i].Name);
mycurrent_cell.appendChild(currenttext);
mycurrent_cell.style.border = "1px solid #000";
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
for(var j=0;j<obj.RowCount;j++)
{
var objRow = obj.Rows[j];
mycurrent_row = document.createElement("tr");
for(i=0;i<objRow.Columns.length;i++)
{
mycurrent_cell = document.createElement("td");
if(objRow.Columns[i].Value != null)
currenttext = document.createTextNode(objRow.Columns[i].Value + " ");
else
currenttext = document.createTextNode(" ");
mycurrent_cell.appendChild(currenttext);
mycurrent_cell.style.border = "1px solid #000";
mycurrent_row.appendChild(mycurrent_cell);
}
mytablebody.appendChild(mycurrent_row);
}
mytable.appendChild(mytablebody);
newdiv.appendChild(mytable);

}
function Error_Test(obj)
{
alert(obj.ErrMsg);
}



function CallTest1()
{
var x = new Array();
x[0] = "Murli";
x[1] = " D";
Test1(x);
}
function NameLength1(obj)
{
alert(obj.Name);
}
function Error_Test1(obj)
{
alert(obj.ErrMsg);
}

function CallTest2()
{
var x = new Object();
x.Name = "Murli, D";
x.Phone = 25460645;
x.Email = "murlid@xyz.com";
Test2(x);
}
function NameLength2(obj)
{
alert(obj);
}
function Error_Test2(obj)
{
alert(obj.ErrMsg);
}

function CallBack_ReturnArray(arrObj)
{
var Total=0;
for(var i in arrObj)
Total+=parseInt(arrObj[i],10);

alert(Total);
}


function CallBack_ReturnStrArray(arrObj)
{
var str='';
for(var i in arrObj)
str+=arrObj[i]+"\n";

alert(str);
}

function CallBack_ReturnObject(clsObj)
{

alert(clsObj.Email +' '+ clsObj.Phone);
}

function CallBack_ReturnFArray(arrObj)
{
var Total=0;
for(var i in arrObj)
Total+=parseFloat(arrObj[i],10);

alert(Total);
}

</script>

</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<div style="border: solid 1px yellow">
Enter Emp No Here:
<input type="text" id="txtClientId" />
<a href="#" onclick="CallTest()">Retrieve Emp</a>
<div id="EmpData">
</div>
</div>
<br />
<div style="border: solid 1px blue">
Pass Array Object:
<a href="#" onclick="CallTest1()">Click Here</a>
<div id="Div1">
</div>
</div>
<br />
<div style="border: solid 1px green">
Pass Class Object:
<a href="#" onclick="CallTest2()">Click Here</a>
<div id="Div2">
</div>
</div>
<br />
<div style="border: solid 1px orange">
Return Array Object:
<a href="#" onclick="ReturnArray()">Click Here</a>
<div id="Div3">
</div>
</div>
<br />
<div style="border: solid 1px brown">
Return String Array Object:
<a href="#" onclick="ReturnStrArray()">Click Here</a>
<div id="Div5">
</div>
</div>
<br />
<div style="border: solid 1px pink">
Return Double Array Object:
<a href="#" onclick="ReturnFArray()">Click Here</a>
<div id="Div6">
</div>
</div>
<br />
<div style="border: solid 1px gray">
Return Class Object:
<a href="#" onclick="ReturnObject()">Click Here</a>
<div id="Div4">
</div>
</div>
<br />
<div style="border: solid 1px red">
Access this textbox from Ajax dll
<asp:TextBox runat="server" ID="txt"></asp:TextBox>
<a href="#" onclick="TestSub()">Get Error</a>
</div>
</div>

<asp:UpdatePanel runat="server" ID="UP1">
<ContentTemplate>
<asp:TextBox runat="server" ID="txt1">
</asp:TextBox>
<asp:Button runat="server" ID="b1" Text="click here" OnClick="b1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

=======For Backend Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace DemoAjaxApp
{
public class Temp
{
string _name, _email;
int _phone;
public string Name { get { return _name; } set { _name = value; } }
public int Phone { get { return _phone; } set { _phone = value; } }
public string Email { get { return _email; } set { _email = value; } }

}
public partial class _Default : System.Web.UI.Page
{
[Ajax.AjaxMethod("Test", "NameLength", null, true, "Loading...")]
public DataTable Test(string Id)
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("server=murli;Database=murli;User Id=sa;Password=");
System.Data.SqlClient.SqlDataAdapter Adp = new System.Data.SqlClient.SqlDataAdapter("Select * from emp where no=" + Id, con);

DataTable dt = new DataTable();
try
{
Adp.Fill(dt);
if (dt.Rows.Count > 0)
return dt;
else
return null;
}
catch (Exception ex)
{
return null;
}
}

[Ajax.AjaxMethod("Test1", "NameLength1", null, false, "Loading...")]
public Temp Test1(string[] str)
{
Temp t1 = new Temp();
foreach (string st in str)
t1.Name += st;

return t1;
}

[Ajax.AjaxMethod("Test2", "NameLength2", null, true, "Loading...")]
public int Test2(Temp str)
{
return str.Name.Length;
}

[Ajax.AjaxMethod("TestSub", false, false, true, "Loading...")]
public void TestSub(string str)
{
txt.Text = (str);
}

[Ajax.AjaxMethod(null, true, false, true, "Loading...")]
public int[] ReturnArray()
{
int[] i ={ 1, 2, 3, 4 };
return i;
}

[Ajax.AjaxMethod]
public string[] ReturnStrArray()
{
string[] str ={ "1", "2", "3", "4" };
return str;
}

[Ajax.AjaxMethod(null, true, false, true, "Loading...")]
public double[] ReturnFArray()
{
double[] i ={ 1.423, 2.543, 3.765, 4.65 };
return i;
}

[Ajax.AjaxMethod(null, true, false, true, "Loading...")]
public Temp ReturnObject()
{
Temp obj = new Temp();
obj.Name = "hello";
obj.Phone = 420840;
obj.Email = "hello@helo.com";
return obj;
}

protected void Page_Load(object sender, EventArgs e)
{
//Ajax.Utility.GenerateMethodScripts(this);
Ajax.Utility.GenerateMethodScripts(this);
}

protected void b1_Click(object sender, EventArgs e)
{
txt1.Text = "hello";
}
}
}


Download Ajax DLL

Monday, September 27, 2010

Encrypt And Decrypt String in SQL

In Sql Server Provided some function to Encrypt and Decrypt the Strings Ex :

For testing purpose i have created one table called login_details you need to be set the password column is varbinay because the password string stored in binary format and length should be min 60

First Create the table :-

create table login_details(uid integer,username varchar(10),password varbinary(100))

Insert Some records on the EncryptByPassPhrase function first parameter used to generate the key for encryption/decryption and second parameter show the password string---

insert into login_details(uid,username,password) values(1,'murli',EncryptByPassPhrase('12','XXX'))

insert into login_details(uid,username,password) values(2,'deepak',EncryptByPassPhrase('12','YYY'))

insert into login_details(uid,username,password) values(3,'sanjay',EncryptByPassPhrase('12','ZZZ'))


For Decryption we need to write code same here:-

select uid,username, DECRYPTBYPASSPHRASE ('12',password) as Password from login_details

select uid,username,convert(varchar(10), DECRYPTBYPASSPHRASE ('12',password)) from login_details

For More Details

Wednesday, September 22, 2010

Call Web services From Javascript in ASP.NET

There is two ways to call web services in your web site using java-script(j Query).

I am writing an example for both:--

This is First Method :Need to include j Query Library file
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function()
{
/*First Method to retriving data*/
$.ajax({
type: "POST",
url: "EmployeeService.asmx/GetEmployeeList",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(list) {
$("#Something").append("<ul id='bullets'></ul>");
for (i = 0; i < list.d.length; i++) {
$("#bullets").append("<li>" + list.d[i].Title + " : " + list.d[i].FirstName + " : " + list.d[i].LastName + " : " + list.d[i].BirthDate + "</li>");
}
},
error: function(e) {
$("#Something").html("There is an error retriving records 1");
}
});
</script>

This is Second Method :-
Need to include j Query Library file
And jmsajax.js File
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"/>
<script src="Scripts/jquery.jmsajax.js" type="text/javascript"/>


<script type="text/javascript">
/*Second Method to retriving data*/
$.jmsajax({
url: "EmployeeService.asmx",
method: "GetEmployeeList",
dataType: "msjson",
success: function(list) {
$("#Something").append("<ul id='bullets'></ul>");
for (i = 0; i < list.length; i++) {
$("#bullets").append("<li>" + list[i].FirstName + " : " + list[i].LastName + " : " + list[i].BirthDate + "</li>");
}
},
error: function(e) {
$("#Something").html("There was an error retreiving records 2");
}
});


});
</script>

Common Content For Both Methods
This is common body content Need to place in your body section

<body>
<form id="form1" runat="server">
<div id="Something">
</div>
</form>
</body>

This is Web service must be in your project..

This is Webservice page (EmployeeService.asmx)

<%@ WebService Language="C#" CodeBehind="~/App_Code/EmployeeService.cs" Class="EmployeeService" %>

And in the Code file you need to create your own code for ex:-

I am coping the entire code file here

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;

///
/// Summary description for EmployeeService
///

[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 EmployeeService : System.Web.Services.WebService {

public EmployeeService () {

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


[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
[System.Web.Services.WebMethod]
public List GetEmployeeList()
{
string Con = System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
var empList = new List();
using (SqlConnection Sqlcon = new SqlConnection(Con))
{
Sqlcon.Open();

string Sql = "Select top 5 Title,FirstName,LastName,BirthDate from tblEmployee";
using (SqlCommand Sqlcmd = new SqlCommand(Sql, Sqlcon))
{
SqlDataReader Sqldr = Sqlcmd.ExecuteReader(CommandBehavior.CloseConnection);
if (Sqldr != null)
{
while (Sqldr.Read())
{
var emp = new Employee
{
Title = Sqldr.GetString(0),
FirstName = Sqldr.GetString(1),
LastName = Sqldr[2].ToString(),
BirthDate = Sqldr.GetDateTime(3)
};
empList.Add(emp);
}
}
return empList;
}
}
}

public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public DateTime BirthDate { get; set; }
}
}

Get the Control ID that Raised PostBack in CodeBehind file of ASP.Net

Control c = GetPostBackControl(Page);
if ((c != null))
{
if (c.ID.ToString() == "grdTemplate" || c.ID.ToString() == "btnAddTemplate")
{
// Do code whatever you want to action while clicked this button.
}
}

////////////////////////Method to get the Postback button Id///////////////
private Control GetPostBackControl(System.Web.UI.Page page)
{
Control control = null;

string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if ((ctrlname != null) & ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if (c is System.Web.UI.WebControls.Button)
{
control = c;
break; // TODO: might not be correct. Was : Exit For
}
}
}
return control;
}


For More Information Click Me

Tuesday, September 14, 2010

Show client side alert message from server side code even when update panel is used

Developers might want to display client side message with information from server side to their users when they have completed some execution at server side. People may try in different way for this purpose.

For example:
Response.Write() method with JavaScript code inside the method:

string mes = "Hello Dhaka";
Response.Write("< script language=”javascript” type=”text/javascript”>alert(’” + mes + “‘);</script>");

or ClientScript.RegisterStartupScript() method:

string message = "";
if (!ClientScript.IsStartupScriptRegistered("mes"))
{
ClientScript.RegisterStartupScript(this.GetType(), "mes", message);
}

But these code doesn't work when you use update panel in your page. So better solution is to use ScriptManager.RegisterStartupScript() method. This works whether update panel is used or not. So let's see the code snippet below:

string message = string.IsNullOrEmpty(TextBox1.Text) ? "Please give a text to textbox." : "You have given: " + TextBox1.Text.Trim();
string script = "";
ScriptManager.RegisterStartupScript(Page, this.GetType(), "AlertMessage", script, false);


OR


System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append(@"<script language='javascript'>");

sb.Append(@"var lbl = document.getElementById('lblDisplayDate');");

sb.Append(@"lbl.style.color='red';");

sb.Append(@"</script>");


if (!ClientScript.IsStartupScriptRegistered("JSScript"))

{

ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb.ToString());

}





With this code snippet you can display a modal message that their data was saved or updated successfully or not.