Sponsored Ad

Monday, June 14, 2010

CompareValidator in ASP.NET | How to Compaire Two String Values in ASP.NET

CompareValidator in ASP.NET | How to Compaire Two String Values in ASP.NET

ASP.NET 2.0 provide number of client side validation controls. One control is CompareValidator, which help to compare two values at client side without writing a javascript code. This example helps you to compare two string values without writing extra code.

Just assign ControlToValidate="txtName1" ControlToCompare="txtName2" the name of two textboxes need to compare and all is done.

 

CompareValidator in ASP.NET | How to Compaire Two String Values in ASP.NET Example:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<body>
    <form id="Form1" runat="server">
        <h4>
            Compare two values</h4>
        Value 1:
        <asp:TextBox ID="txtName1" runat="server" />
        <br />
        <br />
        Value 2:
        <asp:TextBox ID="txtName2" runat="server" />
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" Text="Validate" runat="server" />
        <br />
        <br />
        <br />
        <asp:CompareValidator ID="compair_values" Display="dynamic" ControlToValidate="txtName1" ControlToCompare="txtName2"
            ForeColor="red" Type="String" Text="Validation Failed!"
            runat="server" />
    </form>
</body>
</html>

Sunday, June 6, 2010

How to Generate Random Links in ASP-C#

 

How to Generate Random Links in ASP-C#

Sometimes we need to display random links while designing a web application. Here is a solution to implement this using ASP.NET-C# coding.

This is implemented using random number generator and then checking these number and display the url on the basis of generated numbers.

How to Generate Random Links in ASP-C# Example:

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html>
<body>

<%
Random r = new Random();

double dd = r.NextDouble() ;
if (dd > 0.7)
    Response.Write("<a href='#>C# Tutorials</a>");
else if (dd > .5)
    Response.Write("<a href='#'>Software Testing Tutorials</a>");
else
    Response.Write("<a href='#>SharePoint Tutorials</a>");

%>
<p>
Example of random link generator.
</p>

</body>
</html>

Friday, June 4, 2010

How to Redirect User to Different URL – Radio Buttons - using ASP-C#

 

How to Redirect User to Different URL – Radio Buttons - using ASP-C#

This example help you to code a asp.net C# coding to redirect the user to specific url on selecting a radio button.

 

How to Redirect User to Different URL – Radio Buttons - using ASP-C#

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<%
    if (Request.Form["select"] != null && Request.Form["select"] != "")
       Response.Redirect(Request.Form["select"]);

%>  

<html>
<body>
<form action="Default3.aspx" method="post">
<input type="radio" name="select"
value="#">
C# Tutorials<br>
<input type="radio" name="select"
value="#">
Software Testing Tutorials<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Sponsored Ad

Development Updates