Tuesday, July 21, 2009
ASP.NET AJAX SlideShow Extender - Some Common Tips and Tricks
ASP.NET AJAX SlideShow Extender - Some Common Tips and Tricks
SlideShow is cool extender control that comes with the ASP.NET AJAX control toolkit and can be used to create a Slide show by looping images in a round robin fashion. The images are configured with the SlideShow by using a PageMethod or a webservice. In this article, we will see common tips and tricks while using the SlideShow Extender control. In this article, I assume that you are familiar with the SlideShow Extender. If you want to know more about this control, check the documentation over here.
The Ajax Control Toolkit is a separate download that is built on top of the Microsoft ASP.NET Ajax framework. The toolkit allows you to create extenders and controls to enhance the current ASP.NET server controls.
The toolkit can be downloaded from http://tinyurl.com/ajax-toolkit. Information on how to install the toolkit can be found at http://tinyurl.com/toolkit-info. Let us get started.
How to create a Slide Show with images kept on your local disk using the ASP.NET AJAX SlideShow Extender
Here’s a simple demonstration of creating a Slide Show with the images on your disk, using the ASP.NET AJAX SlideShow Extender. I have created an ASP.NET 3.5 website. Drag and drop the SlideShow Extender from the AJAX Control Toolkit on to the page. Create a folder called ‘images’ in your project and add some images to them. After setting a few properties on the SlideShow, the markup would look similar to the following.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
As shown in the markup, the SlideShow requires a PageMethod called GetSlides that will be called to supply images. Add the following PageMethod GetSlides() in your Default.aspx.cs or .vb that returns a Slide array to the SlideShow Extender control
C#
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{
AjaxControlToolkit.Slide[] imgSlide = new AjaxControlToolkit.Slide[4];
imgSlide[0] = new AjaxControlToolkit.Slide("images/Autumn Leaves.jpg","Autumn","Autumn Leaves");
imgSlide[1] = new AjaxControlToolkit.Slide("images/Creek.jpg","Creek","Creek");
imgSlide[2] = new AjaxControlToolkit.Slide("images/Desert Landscape.jpg", "Landscape", "Landscape");
imgSlide[3] = new AjaxControlToolkit.Slide("images/Dock.jpg","Dock","Dock");
return (imgSlide);
}
VB.NET
_
Public Shared Function GetSlides() As AjaxControlToolkit.Slide()
Dim imgSlide(3) As AjaxControlToolkit.Slide
imgSlide(0) = New AjaxControlToolkit.Slide("images/Autumn Leaves.jpg","Autumn","Autumn Leaves")
imgSlide(1) = New AjaxControlToolkit.Slide("images/Creek.jpg","Creek","Creek")
imgSlide(2) = New AjaxControlToolkit.Slide("images/Desert Landscape.jpg", "Landscape", "Landscape")
imgSlide(3) = New AjaxControlToolkit.Slide("images/Dock.jpg","Dock","Dock")
Return (imgSlide)
End Function
When you run the application, you can see a Slide Show of the images as shown below.
Smooth and Simple!
How to change the time interval between slides at runtime in the ASP.NET AJAX SlideShow Extender
A simple yet effective way is to use JavaScript.
To do so, first add one textbox(txtInterval) and a HTML button control to the page. On clicking the button, the time value in the textbox will be passed to a JavaScript function called changeSlideTime(). In this function, we will retrieve the behavior id of the SliderExtender and then use the set_interval() method of the timer, to increase or decrease the play duration between two slides.
Add the following JavaScript code in the element of your page. The code uses the set_interval() function of the timer to change the Time Interval in between two slides.
Note: The Time duration is to be supplied in milliseconds. So to create a play duration of 10 seconds between two slides, pass a value of 10000.
How to Skip certain Slides based on a condition in the ASP.NET AJAX SlideShow Extender
In order to skip slides based on a certain condition, use the slideChanging event and specify the slide index to be skipped. Then use the set_cancel(true) to skip the slide as shown below:
How to Fade In Fade Out Images in the ASP.NET AJAX SlideShow Extender.
Raymon Wen demonstrated a way to create animations with images in the SlideShow Extender using AnimationExtenders. Add an AnimationExtender from the AJAX Control Toolbox to the page. Configure the FadeIn FadeOut sequences as shown in the mark up over here:
Now in the section of the page, add the following JavaScript code to play the animation during the slideChanging event as shown below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
I hope you enjoyed these tips with the SlideShow Extender control. If you have used any useful hacks or tips with this control, use the comments section to share it with the viewers. I hope you liked the article and I thank you for viewing it.
SlideShow is cool extender control that comes with the ASP.NET AJAX control toolkit and can be used to create a Slide show by looping images in a round robin fashion. The images are configured with the SlideShow by using a PageMethod or a webservice. In this article, we will see common tips and tricks while using the SlideShow Extender control. In this article, I assume that you are familiar with the SlideShow Extender. If you want to know more about this control, check the documentation over here.
The Ajax Control Toolkit is a separate download that is built on top of the Microsoft ASP.NET Ajax framework. The toolkit allows you to create extenders and controls to enhance the current ASP.NET server controls.
The toolkit can be downloaded from http://tinyurl.com/ajax-toolkit. Information on how to install the toolkit can be found at http://tinyurl.com/toolkit-info. Let us get started.
How to create a Slide Show with images kept on your local disk using the ASP.NET AJAX SlideShow Extender
Here’s a simple demonstration of creating a Slide Show with the images on your disk, using the ASP.NET AJAX SlideShow Extender. I have created an ASP.NET 3.5 website. Drag and drop the SlideShow Extender from the AJAX Control Toolkit on to the page. Create a folder called ‘images’ in your project and add some images to them. After setting a few properties on the SlideShow, the markup would look similar to the following.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
As shown in the markup, the SlideShow requires a PageMethod called GetSlides that will be called to supply images. Add the following PageMethod GetSlides() in your Default.aspx.cs or .vb that returns a Slide array to the SlideShow Extender control
C#
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{
AjaxControlToolkit.Slide[] imgSlide = new AjaxControlToolkit.Slide[4];
imgSlide[0] = new AjaxControlToolkit.Slide("images/Autumn Leaves.jpg","Autumn","Autumn Leaves");
imgSlide[1] = new AjaxControlToolkit.Slide("images/Creek.jpg","Creek","Creek");
imgSlide[2] = new AjaxControlToolkit.Slide("images/Desert Landscape.jpg", "Landscape", "Landscape");
imgSlide[3] = new AjaxControlToolkit.Slide("images/Dock.jpg","Dock","Dock");
return (imgSlide);
}
VB.NET
Public Shared Function GetSlides() As AjaxControlToolkit.Slide()
Dim imgSlide(3) As AjaxControlToolkit.Slide
imgSlide(0) = New AjaxControlToolkit.Slide("images/Autumn Leaves.jpg","Autumn","Autumn Leaves")
imgSlide(1) = New AjaxControlToolkit.Slide("images/Creek.jpg","Creek","Creek")
imgSlide(2) = New AjaxControlToolkit.Slide("images/Desert Landscape.jpg", "Landscape", "Landscape")
imgSlide(3) = New AjaxControlToolkit.Slide("images/Dock.jpg","Dock","Dock")
Return (imgSlide)
End Function
When you run the application, you can see a Slide Show of the images as shown below.
Smooth and Simple!
How to change the time interval between slides at runtime in the ASP.NET AJAX SlideShow Extender
A simple yet effective way is to use JavaScript.
To do so, first add one textbox(txtInterval) and a HTML button control to the page. On clicking the button, the time value in the textbox will be passed to a JavaScript function called changeSlideTime(). In this function, we will retrieve the behavior id of the SliderExtender and then use the set_interval() method of the timer, to increase or decrease the play duration between two slides.
Add the following JavaScript code in the element of your page. The code uses the set_interval() function of the timer to change the Time Interval in between two slides.
Note: The Time duration is to be supplied in milliseconds. So to create a play duration of 10 seconds between two slides, pass a value of 10000.
How to Skip certain Slides based on a condition in the ASP.NET AJAX SlideShow Extender
In order to skip slides based on a certain condition, use the slideChanging event and specify the slide index to be skipped. Then use the set_cancel(true) to skip the slide as shown below:
How to Fade In Fade Out Images in the ASP.NET AJAX SlideShow Extender.
Raymon Wen demonstrated a way to create animations with images in the SlideShow Extender using AnimationExtenders. Add an AnimationExtender from the AJAX Control Toolbox to the page. Configure the FadeIn FadeOut sequences as shown in the mark up over here:
Now in the section of the page, add the following JavaScript code to play the animation during the slideChanging event as shown below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
I hope you enjoyed these tips with the SlideShow Extender control. If you have used any useful hacks or tips with this control, use the comments section to share it with the viewers. I hope you liked the article and I thank you for viewing it.
Labels: ASP.NET AJAX SlideShow Extender
Code For Remember Me password Checked
protected void UserLogin(object sender, EventArgs e)------>Button_Click
{
if (Membership.ValidateUser(UserName.Text, PassWord.Text))
{
if (RememberDetailsChecked.Checked)
{
HttpCookie c1, c2;
c1 = new HttpCookie("username");
c2 = new HttpCookie("pasword");
c1.Value = UserName.Text;
c2.Value = PassWord.Text;
c1.Expires = DateTime.Now.AddDays(7);
c2.Expires = DateTime.Now.AddDays(7);
Response.AppendCookie(c1);
Response.AppendCookie(c2);
}
else
{
HttpCookie obj1, obj2;
obj1 = Request.Cookies["username"];
obj2 = Request.Cookies["pasword"];
if (obj1 != null && obj2 != null)
{
obj2.Expires = DateTime.Now.AddDays(-1);
Response.AppendCookie(obj2);
}
}
setCookie(UserName.Text);
}
else
{
LoginErrorLabel.Text = "Enter Valid Details *";
}
}
code in page_load...........
if (!Page.IsPostBack)
{
HttpCookie obj1, obj2;
obj1 = Request.Cookies["username"];
obj2 = Request.Cookies["pasword"];
if (obj1 != null && obj2 != null)
{
if(Membership.ValidateUser(obj1.Value, obj2.Value))
{
UserName.Text = obj1.Value;
PassWord.Attributes.Add("value", obj2.Value);
RememberDetailsChecked.Checked = true;
}
}
}
{
if (Membership.ValidateUser(UserName.Text, PassWord.Text))
{
if (RememberDetailsChecked.Checked)
{
HttpCookie c1, c2;
c1 = new HttpCookie("username");
c2 = new HttpCookie("pasword");
c1.Value = UserName.Text;
c2.Value = PassWord.Text;
c1.Expires = DateTime.Now.AddDays(7);
c2.Expires = DateTime.Now.AddDays(7);
Response.AppendCookie(c1);
Response.AppendCookie(c2);
}
else
{
HttpCookie obj1, obj2;
obj1 = Request.Cookies["username"];
obj2 = Request.Cookies["pasword"];
if (obj1 != null && obj2 != null)
{
obj2.Expires = DateTime.Now.AddDays(-1);
Response.AppendCookie(obj2);
}
}
setCookie(UserName.Text);
}
else
{
LoginErrorLabel.Text = "Enter Valid Details *";
}
}
code in page_load...........
if (!Page.IsPostBack)
{
HttpCookie obj1, obj2;
obj1 = Request.Cookies["username"];
obj2 = Request.Cookies["pasword"];
if (obj1 != null && obj2 != null)
{
if(Membership.ValidateUser(obj1.Value, obj2.Value))
{
UserName.Text = obj1.Value;
PassWord.Attributes.Add("value", obj2.Value);
RememberDetailsChecked.Checked = true;
}
}
}
Labels: RememberMe checked in login using ASP.Net and C#.net
Examples of applying custom date/time format strings are shown in the following table.
Friday, July 10, 2009
What are the access-specifiers available in c#?
1. Public: Any member declared public can be accessed from
outside the class.
2. Private: it allows a class to hide its member variables
and member functions from other class objects and function.
Therefore, the private member of a class is not visible
outside a class. if a member is declared private, only the
functions of that class access the member.
3. Protected: This also allows a class to hide its member
var. and member func. from other class objects and
function, except the child class. it becomes important
while implementing inheritance.
4. Internal: Internal member can be expose to other
function and objects. it can be accessed from any class or
method defined within the application in which the member
is defined
5. Protected Internal: it's similar to Protected access
specifier, it also allows a class to hide its member
variables and member function to be accessed from other
class objects and function, excepts child class, within the
application. used while implementing inheritance.
An access specifier determines how other parts of a program
can access a class member.
Member access is controled by five access specifiers:
1. public,
2. private,
3. protected,
4. internal.
5. protected internal
1. public member can be accessed by any other code in
your program.
2. Main() is declared as public because it will be called
by code outside of its class (the operating system).
3. private member can be accessed only by other members
of its class.
4. A protected member is public within a class hierarchy,
but private outside that hierarchy.
5. A protected member is created by using the protected
access modifier.
6. The internal modifier declares that a member is known
throughout all files in an assembly, but unknown outside
that assembly.
7. The protected internal access level can be given only
to class members.
8. A member declared with protected internal access is
accessible within its own assembly or to derived types.
outside the class.
2. Private: it allows a class to hide its member variables
and member functions from other class objects and function.
Therefore, the private member of a class is not visible
outside a class. if a member is declared private, only the
functions of that class access the member.
3. Protected: This also allows a class to hide its member
var. and member func. from other class objects and
function, except the child class. it becomes important
while implementing inheritance.
4. Internal: Internal member can be expose to other
function and objects. it can be accessed from any class or
method defined within the application in which the member
is defined
5. Protected Internal: it's similar to Protected access
specifier, it also allows a class to hide its member
variables and member function to be accessed from other
class objects and function, excepts child class, within the
application. used while implementing inheritance.
An access specifier determines how other parts of a program
can access a class member.
Member access is controled by five access specifiers:
1. public,
2. private,
3. protected,
4. internal.
5. protected internal
1. public member can be accessed by any other code in
your program.
2. Main() is declared as public because it will be called
by code outside of its class (the operating system).
3. private member can be accessed only by other members
of its class.
4. A protected member is public within a class hierarchy,
but private outside that hierarchy.
5. A protected member is created by using the protected
access modifier.
6. The internal modifier declares that a member is known
throughout all files in an assembly, but unknown outside
that assembly.
7. The protected internal access level can be given only
to class members.
8. A member declared with protected internal access is
accessible within its own assembly or to derived types.
Labels: access-specifiers, What are the access-specifiers available in c#?
What is the difference between windows authentication and sql server authentication
In simple words
Windows authentication is highly secure than SQL Server authentication why because we need not provide any login details. So the chance of tracing login details from code by the unauthorized persons will be less. Windows authentication uses the default windows login credentials.
SQL Authentication :
SQL Authentication is the typical authentication used for
various database systems, composed of a username and a
password. Obviously, an instance of SQL Server can have
multiple such user accounts (using SQL authentication) with
different usernames and passwords. In shared servers where
different users should have access to different databases,
SQL authentication should be used. Also, when a client
(remote computer) connects to an instance of SQL Server on
other computer than the one on which the client is running,
SQL Server authentication is needed. Even if you don't
define any SQL Server user accounts, at the time of
installation a root account - sa - is added with the
password you provided. Just like any SQL Server account,
this can be used to log-in localy or remotely, however if
an application is the one that does the log in, and it
should have access to only one database, it's strongly
recommended that you don't use the sa account, but create a
new one with limited access. Overall, SQL authentication is
the main authentication method to be used while the one we
review below - Windows Authentication - is more of a
convenience.
Windows Authentication :
When you are accessing SQL Server from the same computer it
is installed on, you shouldn't be prompted to type in an
username and password. And you are not, if you're using
Windows Authentication. With Windows Authentication, the
SQL Server service already knows that someone is logged in
into the operating system with the correct credentials, and
it uses these credentials to allow the user into its
databases. Of course, this works as long as the client
resides on the same computer as the SQL Server, or as long
as the connecting client matches the Windows credentials of
the server. Windows Authentication is often used as a more
convenient way to log-in into a SQL Server instance without
typing a username and a password, however when more users
are envolved, or remote connections are being established
with the SQL Server, SQL authentication should be used.
There is a difference between 'Authentication' and 'Authentication mode' in SQL Server 2005.
Authentication (2 types) - Windows and SQL Server Authentication.
Authentication mode (2 types) - Windows Authentication mode and Mixed Mode.
When using 'Windows authentication mode' you can only use Windows authentication to connect to SQL Server. When using 'Mixed mode' you can use either 'Windows authentication' or 'SQL Server authentication' to connect to SQL Server 2005
When to use what?
'Windows Authentication Mode' is much more secure than Mixed Mode. Windows Authentication utilizes Kerberos security protocol. Remember that in a typical installation, Windows Authentication is the default security mode. So when a user having a Windows user account connects to SQL Server, the server validates the account credentials using information in the Windows operating system.
SQL Server Authentication is provided for backward compatibility only. Whenever possible, use Windows Authentication.
If all the users users accessing the database are Microsoft Windows users, use 'Windows authentication mode' . If your environment consists of Windows users and Non-Windows users use 'Mixed mode'.
Windows authentication is highly secure than SQL Server authentication why because we need not provide any login details. So the chance of tracing login details from code by the unauthorized persons will be less. Windows authentication uses the default windows login credentials.
SQL Authentication :
SQL Authentication is the typical authentication used for
various database systems, composed of a username and a
password. Obviously, an instance of SQL Server can have
multiple such user accounts (using SQL authentication) with
different usernames and passwords. In shared servers where
different users should have access to different databases,
SQL authentication should be used. Also, when a client
(remote computer) connects to an instance of SQL Server on
other computer than the one on which the client is running,
SQL Server authentication is needed. Even if you don't
define any SQL Server user accounts, at the time of
installation a root account - sa - is added with the
password you provided. Just like any SQL Server account,
this can be used to log-in localy or remotely, however if
an application is the one that does the log in, and it
should have access to only one database, it's strongly
recommended that you don't use the sa account, but create a
new one with limited access. Overall, SQL authentication is
the main authentication method to be used while the one we
review below - Windows Authentication - is more of a
convenience.
Windows Authentication :
When you are accessing SQL Server from the same computer it
is installed on, you shouldn't be prompted to type in an
username and password. And you are not, if you're using
Windows Authentication. With Windows Authentication, the
SQL Server service already knows that someone is logged in
into the operating system with the correct credentials, and
it uses these credentials to allow the user into its
databases. Of course, this works as long as the client
resides on the same computer as the SQL Server, or as long
as the connecting client matches the Windows credentials of
the server. Windows Authentication is often used as a more
convenient way to log-in into a SQL Server instance without
typing a username and a password, however when more users
are envolved, or remote connections are being established
with the SQL Server, SQL authentication should be used.
There is a difference between 'Authentication' and 'Authentication mode' in SQL Server 2005.
Authentication (2 types) - Windows and SQL Server Authentication.
Authentication mode (2 types) - Windows Authentication mode and Mixed Mode.
When using 'Windows authentication mode' you can only use Windows authentication to connect to SQL Server. When using 'Mixed mode' you can use either 'Windows authentication' or 'SQL Server authentication' to connect to SQL Server 2005
When to use what?
'Windows Authentication Mode' is much more secure than Mixed Mode. Windows Authentication utilizes Kerberos security protocol. Remember that in a typical installation, Windows Authentication is the default security mode. So when a user having a Windows user account connects to SQL Server, the server validates the account credentials using information in the Windows operating system.
SQL Server Authentication is provided for backward compatibility only. Whenever possible, use Windows Authentication.
If all the users users accessing the database are Microsoft Windows users, use 'Windows authentication mode' . If your environment consists of Windows users and Non-Windows users use 'Mixed mode'.
Subscribe to Comments [Atom]