Showing posts with label .net questions. Show all posts
Showing posts with label .net questions. Show all posts

Tuesday, 9 August 2016

Write a program to display reverse of string in ASP.NET

This post will help you to demonstrate a program to display the reverse of a string in ASP.NET. You can copy this code after you open a blank project in IDE of ASP.NET(Visual Studio). Then try to run that copied code, at that time you will get an expecting output.

In this program we are trying to find reverse of a string that we entered in text-box. For this, we used one text-box and one label to print output, and a button to perform this function. There you can see these text-box and a button also in the output. But the label will be hidden, it will only visible after you try to find the output.Then enter any string that you want to check its reverse, after that click on the button. Then you will get the output. The output will be reverse of the string that you have entered in the text-box field. We hope this code will help you to be a developer or a programmer. Before copying, try to understand the method that we used to find the output. Click on the read more button to get this code.

Wednesday, 3 August 2016

write a program to print selected value of listbox in asp.net

listbox.aspx.cs

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="listbox.aspx.cs" Inherits="our_program.listbox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<center><h1>LIST BOX AND SELECTED VALUE</h1></center>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div>
               <asp:ListBox ID="blt" runat="server" Height="169px" Width="118px" ></asp:ListBox>
        <br />
        <asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" />
        <br />
        <asp:Label ID="lbl" runat="server" Text="selected value is shown here"></asp:Label>
    
    </div>
    </center>
    </form>
</body>
</html>

listbox.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace our_program
{
    public partial class listbox : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            blt.Items.Add("JAN");
            blt.Items.Add("FEB");
            blt.Items.Add("MAR");
            blt.Items.Add("APR");
            blt.Items.Add("MAY");
            blt.Items.Add("JUN");
            blt.Items.Add("JUL");
            blt.Items.Add("AUG");
            blt.Items.Add("SEP");
            blt.Items.Add("OCT");
            blt.Items.Add("NOV");
            blt.Items.Add("DEC");
        }

        protected void btn_Click(object sender, EventArgs e)
        {
            lbl.Text = "YOU ARE SELECTED MONTH IS :" + blt.SelectedItem.ToString();
        }
    }
}

write asp.net program to print textbox value when a change occur in textbox

textbox_with_label.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="textbox_with_label.aspx.cs" Inherits="our_program.textbox_with_label" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<center>
<h1> TEXTBOX WITH LABEL</h1>
</center>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div>
    <asp:TextBox runat="server" ID="txt" OnTextChanged="textchanged" AutoPostBack="true"></asp:TextBox>
    <br />
    <asp:Label runat="server" ID="lbl" Text="textbox value"></asp:Label>
    </div>
    </center>
    </form>
</body>
</html>

textbox_with_label.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace our_program
{
    public partial class textbox_with_label : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void textchanged(object sender, EventArgs e)
        {
            string a = txt.Text;
            lbl.Text = a.ToString();
        }
    }
}

write asp.net program to print value of radio button when button is clicked

radio_button.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="radio_button.aspx.cs" Inherits="our_program.radio_button" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
             <center><h1>radio button</h1></center>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div>
        <asp:RadioButton ID="rbn1" runat="server" GroupName="radio"  Text="first radio button" />
        <br />
        <asp:RadioButton ID="rbn2" runat="server" GroupName="radio"  Text="second radio button"/>
        <br />
        <asp:RadioButton ID="rbn3" runat="server" GroupName="radio"  Text="third radio button"/>
        <br />
        <asp:Button ID="btn" runat="server" Text="Button" onclick="Button1_Click" />
        <br />
        <asp:Label ID="lbl" runat="server" Text="selected text will shown here"></asp:Label>
    </div>
    </center>
    </form>
</body>
</html>


radio_button.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace our_program
{
    public partial class radio_button : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (rbn1.Checked == true)
            {
                lbl.Text = "Your selected radio button is : " + rbn1.Text;
            }
            if (rbn2.Checked == true)
            {
                lbl.Text = "Your selected radio button is : " + rbn2.Text;
            }
            if (rbn3.Checked == true)
            {
                lbl.Text = "Your selected radio button is : " + rbn3.Text;
            }
        }
    }
}