Step 1: Design Page – PalindromeString.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PalindromeString.aspx.cs" Inherits="PalindromeString" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Palindrome String Checker - Real Time Example</title>
<style>
body {
font-family: Arial;
background-color: #f0f2f5;
margin: 50px;
}
.container {
width: 460px;
margin: auto;
background: white;
border-radius: 8px;
box-shadow: 0px 0px 10px #ccc;
padding: 25px;
}
h2 {
color: #1A2A80;
text-align: center;
}
.form-control {
width: 100%;
padding: 8px;
margin-top: 10px;
}
.btn {
background-color: #7A85C1;
color: white;
border: none;
padding: 10px 20px;
margin-top: 10px;
border-radius: 5px;
cursor: pointer;
width: 100%;
}
.result {
margin-top: 20px;
font-weight: bold;
color: #333;
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<h2>Palindrome String Checker</h2>
<asp:Label ID="lblInput" runat="server" Text="Enter a String:"></asp:Label><br />
<asp:TextBox ID="txtInput" runat="server" CssClass="form-control" placeholder="Example: madam"></asp:TextBox><br />
<asp:Button ID="btnCheck" runat="server" Text="Check Palindrome" CssClass="btn" OnClick="btnCheck_Click" /><br />
<asp:Label ID="lblResult" runat="server" CssClass="result"></asp:Label>
</div>
</form>
</body>
</html>
Step 2: Backend Logic – PalindromeString.aspx.cs
using System;
public partial class PalindromeString : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnCheck_Click(object sender, EventArgs e)
{
string input = txtInput.Text.Trim().ToLower();
if (string.IsNullOrEmpty(input))
{
lblResult.Text = "Please enter a valid string.";
lblResult.ForeColor = System.Drawing.Color.Red;
return;
}
if (IsPalindrome(input))
{
lblResult.Text = $" \"{input}\" is a Palindrome String.";
lblResult.ForeColor = System.Drawing.Color.Green;
}
else
{
lblResult.Text = $" \"{input}\" is NOT a Palindrome String.";
lblResult.ForeColor = System.Drawing.Color.Red;
}
}
private bool IsPalindrome(string str)
{
int left = 0;
int right = str.Length - 1;
while (left < right)
{
if (str[left] != str[right])
return false;
left++;
right--;
}
return true;
}
}
Real-Time Example Flow
Open PalindromeString.aspx in your browser.
Enter a word (e.g., madam ).
Click “Check Palindrome” .
The output displays:
"madam" is a Palindrome String.
Try with another word (e.g., hello ):
"hello" is NOT a Palindrome String.
Explanation
| Step | Description |
|---|
| 1 | Accept input string from user and convert it to lowercase. |
| 2 | Initialize two pointers: one from the start, one from the end. |
| 3 | Compare characters at both ends. |
| 4 | Move inward until all characters are checked. |
| 5 | If all pairs match → Palindrome; otherwise, not. |
Sample Input / Output
| Input | Output |
|---|
| madam | Palindrome |
| level | Palindrome |
| racecar | Palindrome |
| hello | Not Palindrome |
| apple | Not Palindrome |