I have come across new functionality called "stringbuilder" in javascript using Ajax.
please follow the below steps to enable the Stringbuilder.
Step 1:
Add script manager tag in the aspx page.
Step 2:
Example:
<script type="text/javascript">
function buildAString(title)
{
var headTagStart = "";
var headTagEnd = "";
var titleTagStart = "";
var sb = new Sys.StringBuilder(this._headTagStart);
sb.append(titleTagEnd);
sb.append(title);
sb.append(titleTagEnd);
sb.append(headTagEnd);
// Displays: "The result: "
alert("The result" + sb.toString());
}
var title = "A Title";
buildAString(title);
</script>
Sharing knowledge in Project, Program, Portfolio Innovation Management (PPIM) and various Technology.
Tuesday, November 24, 2009
Wednesday, November 11, 2009
Calling Parent Method from child control using Events & Delegates.
Before starting we should very clear about event and delegate
Event: it's handler which will call the delegate and it will call the method.
Delegate: it's a function pointer, it will point to the particular function.
Let me explain about calling parent method from the child control.
Step 1: create one aspx pages and usercontrol pages.
step 2:
In the usercontrol create one button and lable. The scenoria is like this when user click on the button has to call the child method as well as the parent method.
Step 3:
Create one user control with the following code.
Childcontrol.ascx
<asp:Button ID="btnShow" runat="server" />
<asp:Label ID="lblShow" runat="server"></asp:Label>
Childcontrol.ascx.cs
public delegate void callDelegate();
public event callDelegate callEvent;
protected void Page_Load(object sender, EventArgs e)
{
btnShow.Click += delegate
{
lblShow.Text = "Hi how are u";
this.showData();
};
}
protected virtual void showData()
{
if (this.callEvent != null)
{
this.callEvent();
}
}
Step 4:
Create one aspx page with name of Parent with the following code.
parent.aspx
<%@ Register Src="~/UserControl/Childuser.ascx" TagPrefix="child" TagName="UC" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblParent" runat="server"></asp:Label>
<child:UC id="UC1" runat="server"></child:UC>
</div>
</form>
</body>
</html>
parent.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
UC1.callEvent += new Childuser.callDelegate(UC1_callEvent);
}
void UC1_callEvent()
{
lblParent.Text = "Hi Parent";
}
Event: it's handler which will call the delegate and it will call the method.
Delegate: it's a function pointer, it will point to the particular function.
Let me explain about calling parent method from the child control.
Step 1: create one aspx pages and usercontrol pages.
step 2:
In the usercontrol create one button and lable. The scenoria is like this when user click on the button has to call the child method as well as the parent method.
Step 3:
Create one user control with the following code.
Childcontrol.ascx
<asp:Button ID="btnShow" runat="server" />
<asp:Label ID="lblShow" runat="server"></asp:Label>
Childcontrol.ascx.cs
public delegate void callDelegate();
public event callDelegate callEvent;
protected void Page_Load(object sender, EventArgs e)
{
btnShow.Click += delegate
{
lblShow.Text = "Hi how are u";
this.showData();
};
}
protected virtual void showData()
{
if (this.callEvent != null)
{
this.callEvent();
}
}
Step 4:
Create one aspx page with name of Parent with the following code.
parent.aspx
<%@ Register Src="~/UserControl/Childuser.ascx" TagPrefix="child" TagName="UC" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblParent" runat="server"></asp:Label>
<child:UC id="UC1" runat="server"></child:UC>
</div>
</form>
</body>
</html>
parent.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
UC1.callEvent += new Childuser.callDelegate(UC1_callEvent);
}
void UC1_callEvent()
{
lblParent.Text = "Hi Parent";
}
Monday, November 9, 2009
Base Pages using C#.Net
Now i am come with the scenario clearing the session on each page writing the code.
for clearing the session in common place.
we can use some thing called base pages. so that we can keep the code in seprate place.
Step 1:
Create one class file with the name of basepages.cs.
This will contain the one method which will clear the session objects permanently.
Example:
public class BasePages:System.Web.UI.Page
{
public void clearSession()
{ if (Page.User.Identity.IsAuthenticated == false)
{ Session.Abandon();
Response.Redirect("login.aspx");
}
}
}
step 2
Create one login with the extension of .Aspx page.in the code behind just inherit that base class method.
public partial class SessionCheck : Performance.BasePages
{
protected void Page_Load(object sender, EventArgs e)
{
base.clearSession();
}
}
for clearing the session in common place.
we can use some thing called base pages. so that we can keep the code in seprate place.
Step 1:
Create one class file with the name of basepages.cs.
This will contain the one method which will clear the session objects permanently.
Example:
public class BasePages:System.Web.UI.Page
{
public void clearSession()
{ if (Page.User.Identity.IsAuthenticated == false)
{ Session.Abandon();
Response.Redirect("login.aspx");
}
}
}
step 2
Create one login with the extension of .Aspx page.in the code behind just inherit that base class method.
public partial class SessionCheck : Performance.BasePages
{
protected void Page_Load(object sender, EventArgs e)
{
base.clearSession();
}
}
Thursday, November 5, 2009
Memory Profiler.
This is the tool which will find out memory leakage. using this we can fine tune the code.
download: http://memprofiler.com/
download: http://memprofiler.com/
Subscribe to:
Posts (Atom)