Update Table Query to Update Data From Another Table

Suppose we have two tables names Tbl_Topics & Tbl_TeacherTopics having columns MyTopic, TopicId, TopicName & TeacherTopicID, TopicId, TopicName respectively. now we want to update Tbl_Topics Table with data from Tbl_TeacherTopics for given TeacherTopicID

Query for the above statements is:

UPDATE Tbl_Topics SET TopicID=TT.TopicID,TopicName=TT.TopicName FROM
(SELECT TopicID,TopicName FROM Tbl_TeacherTopics WHERE TeacherTopicID=1062)
AS TT WHERE Tbl_Topics.MyTopic='Lakhan Pal garg'

Top

Java Script Event Handling

Code to handle event with javaScript.

Sample Code:

var pageMgr = Sys.WebForms.PageRequestManager.getInstance();
pageMgr.add_beginRequest(BeforeAjaxRequest);
pageMgr.add_pageLoaded(pageLoadedHandler);
var postbackElement;
function BeforeAjaxRequest(sender,args)
{
postbackElement=args.get_postBackElement();
if (postbackElement.id.indexOf("{ID of the Control}") != "-1")
{
/* Write your Code Here */
}
}
function pageLoadedHandler(sender,args)
{
if (typeof(postbackElement) == "undefined")
{
return;
}
else if (postbackElement.id.indexOf("{ID of the Control}") != "-1")
{
/* Write your Code Here */
}
}

For Example:

You are having a asp link button with id lnkTest now according to this your above code should be:

var pageMgr = Sys.WebForms.PageRequestManager.getInstance();
pageMgr.add_beginRequest(BeforeAjaxRequest);
pageMgr.add_pageLoaded(pageLoadedHandler);
var postbackElement;
function BeforeAjaxRequest(sender, args)
{
postbackElement=args.get_postBackElement();
if (postbackElement.id.indexOf("lnkTest") != "-1")
{
alert("Before Ajax Request");
}
}
function pageLoadedHandler(sender, args)
{
if (typeof(postbackElement) == "undefined")
{
return;
}
else if (postbackElement.id.indexOf("lnkTest") != "-1")
{
alert("After Ajax the Request");
}
}

Top

string v/s StringBuilder

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

Strings are immutable. immutable means every time we alter the string a new object is created. hence lower the performance. while stringBuilder are mutable. so it increase the performance where we need to perform altered, insert and remove operations. But it is not recommended to use StringBuilder always. for small string where you need to perform less operation then use string and in case of large string and more operation use StringBuilder.

Top

ref v/s out Parametes in C#

out and ref looks quite similar in nature.Both parameters are used to return back some value to the caller of the function. But still there is a important difference between them. these two types are used for specific purpose. When we use the out parameter, The program calling the function need not assign a value to the out parameter before making the call to the function. The value of the out parameter has to be set by the function before returning the value.

For a ref type parameter, the value to the parameter has to be assigned before calling the function. If we do not assign the value before calling the function we will get a compiler error. Another important thing to note here is that in case of ref parameter, the value passed by the caller function can be very well used by the called function. The called function does not have the compulsion to assign the value to a ref type parameter. But in case of the out parameter, the called function has to assign a value.

Top