Feeds:
Posts
Comments

Use this attributes to disable copying from your page

<body ondragstart=”return false” onselectstart=”return false”>

Advertisements

Update Panel slow down the speed and increase the page size.So think 100 times before using Update Panel

There are two alternatives of Update Panel

1) Page Method.

2) Web Service.

Here I am giving you the example of filling dropdownlist by the two methods one by one

Filling Dropdownlist by Page Method
1)Page Method
Remember Page Methods will not work in master page

Put these 3 Javascript functions and scriptmanager on Page Source

//Function 1st fro calling pagemethod
function getDegree()
{
var makelist = document.getElementById(”);
var key = makelist.options[makelist.selectedIndex].text;
PageMethods.BindCollegeDegree(key,OnComplete,OnError);
}

//Function 2nd for binding dropdown by spliting the values
function OnComplete(result)
{
var models = document.getElementById(”);
for (var count=models.options.length-1;count > -1; count–)
{
models.options[count] = null;
}
var items = result.split(‘|’);
var idValue;
var textValue;
var optionItem;
for(i = 0; i < items.length;i++)
{
textValue = items[i];
idValue = items[i];
optionItem = new Option( textValue, idValue, false, false);
models.options[i] = optionItem;
}

}

function OnError(error)

{

alert(“Error Occured”);

}

You have to use ScriptManager
In Code Behind OnPage_Load put this line to call javascript function

{

drp1st.Attributes.Add(“onchange”, “return getDegree();”);

}

Write this Method in your code behind.Replace sql query with yours

//Binding Dropdown by using Page Methods

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]

public static string BindCollegeDegree(string degree)

{

string data = “”;

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[“ConnectionString”].ConnectionString);

SqlCommand cmd = new SqlCommand(“SELECT StreamName,StreamID FROM College where DegreeId=@degree”, con);

cmd.Parameters.Add(“@degree”, SqlDbType.NChar).Value = degree.Trim();

con.Open();

try

{

SqlDataReader r = cmd.ExecuteReader();

while (r.Read())

{

data = data + r[“StreamName”].ToString().Trim() + “|”;

}

int len = data.Length;

return data.Substring(0, len – 1);

}

catch (SqlException ex) { return null; }

finally { con.Close(); }

}

2) Web Services
To use web service add asmx file.
Here I have added WebService.asmx
when press f7 on this page, WebService.cs page created, write your business login here

WebService.cs
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Data.SqlClient;
using System.Configuration;

///
/// Summary description for WebService
///
[WebService(Namespace = “http://microsoft.com/webservices/&#8221;)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{

public WebService()
{

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

[WebMethod]
public string BindingSearchDropDown(string key)
{
string data = “”;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[“ConnectionString”].ConnectionString);
if (key == “College”)
{
SqlCommand cmd = new SqlCommand(“SELECT [CourseName], CourseTypeId FROM [College_CourseTypeMaster]”, con);
con.Open();
SqlDataReader r = cmd.ExecuteReader();
while (r.Read())
{
data = data + r[“CourseName”].ToString().Trim() + “|”;
}
return data = data.Substring(0, data.Length – 1);
}
return (“”);
}
}

Put these functions in markup

function getModels()
{
var makelist =document.getElementById(“One”);
var key = makelist.options[makelist.selectedIndex].value;
WebService.BindingSearchDropDown(key,OnGetModelsComplete);

}

function OnGetModelsComplete(result)
{
PopulateModels(result);
}
function PopulateModels(result)
{
var models = document.getElementById(“Two”);
for (var count=models.options.length-1;count > -1; count–)
{
models.options[count] = null;
}
var items = result.split(‘|’);
var idValue;
var textValue;
var optionItem;
for(i = 0; i < items.length;i++)
{
textValue = items[i];
idValue = items[i];
optionItem = new Option( textValue,idValue, false, false);
models.options[i] = optionItem;

}
}

Add ScriptManager on this page

Thats all!
Any query or help please feel free to mail me on this Id
cooolguymca at the rate gmail.com