Sponsored Ad

Wednesday, July 14, 2010

Loop Through RadioButtonList items and get seletec item

This post will help you to loop through all the items of RadioButtonList and find out the selected value. There is a direct method also to find the selected value.

rdoWebsiteList.SelectedItem.ToString()

 

Loop Through RadioButtonList items and get seletec item

 

Loop Through RadioButtonList items and get seletec item Example:

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

<script runat="server">
    protected void btnGetSelected_Click(object sender, EventArgs e)
    {
        lblSelected.Text = "Your selected Radio button value is: <br>";
        foreach (ListItem lst in rdoWebsiteList.Items)
        {
            if (lst.Selected == true)
            {
                lblSelected.Text += lst.Text ;
            }
        }

        lblSelected.Text += "<br>Using Another method: " + rdoWebsiteList.SelectedItem.ToString();
    }
</script>

<html>
<head>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
           <asp:RadioButtonList ID="rdoWebsiteList" runat="server" >
                <asp:ListItem>BharatPad.com</asp:ListItem>
                <asp:ListItem>TestingWiz.com</asp:ListItem>
                <asp:ListItem>SharePointBank.com</asp:ListItem>
                <asp:ListItem>SoftwareTestingNet.com</asp:ListItem>
            </asp:RadioButtonList>
            <br />
            <asp:Button ID="btnGetSelected" runat="server" Text="Get Selected Values" OnClick="btnGetSelected_Click" />
            <br />
            <asp:Label ID="lblSelected" runat="server" Text=""></asp:Label>
        </div>
    </form>
</body>
</html>

Friday, July 9, 2010

How to pass command on button click in C#

This program help to pass command name on button command.

Assign CommandName="MyClick" property for button and in C# check for command name you pass through button.

if(e.CommandName == "MyClick")

 

How to pass command on button click in C#

 

How to pass command on button click in C# Example:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >

<script runat="server">

    protected void btnClick_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "MyClick")
        {
            Response.Write("Click Command Passed");
        }
        else
        {
            Response.Write("Non Click Command Passed");
        }

    }
</script>

<html xmlns="">
<head>
    <title>How pass command on button click.</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnClick"  runat="server" Text="Button" CommandName="MyClick" OnCommand="btnClick_Command" />
        </div>
    </form>
</body>
</html>

Wednesday, July 7, 2010

How to use RegisterClientScriptBlock method to run javascript code in C#

This is an exaple of RegisterClientScriptBlock to run write the javascript code in C# and run it.

The exaple example is given in this code, you can write your own complex code by taking help of this small program.

 

How to use RegisterClientScriptBlock method to run javascript code in C#

How to use RegisterClientScriptBlock method to run javascript code in C#

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        string myScript = @" function RunCode() { alert(' This is example of RegisterClientScriptBlock'); }";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", myScript, true);
    }
</script>

<html xmlns="”>
<head>
    <title>How to use RegisterClientScriptBlock method to run javascript code.</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnClick" Text="Click" runat="server" OnClientClick="RunCode(); return false;" />
        </div>
    </form>
</body>
</html>

Saturday, July 3, 2010

How to show validations in messagebox/popup using ASP.NET

You can show validation messages in popup/message box. You just need to have a validation summary control and add these properties:

ShowMessageBox="true"

ShowSummary="false"

It will display all validation messages in popup alert window, without using javascript.

How to show validations in messagebox/popup using ASP.NET

How to show validations in messagebox/popup using ASP.NET

How to show validations in messagebox/popup using ASP.NET

 

How to show validations in messagebox/popup using ASP.NET Example:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
<html>
<body>
    <form id="Form1" runat="server">
        <h4>
           Popup Validation Summary Example</h4>
        <br />
        Enter UserName Name:
        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtUserName"
            runat="server" ErrorMessage="Please Enter User Name" InitialValue="" Text="*" />
        <br />
        Enter Password: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="txtPassword"
            runat="server" ErrorMessage="Please Enter Password" InitialValue="" Text="*" />
        <br />
        <asp:Button ID="Button1" Text="Submit" runat="server" />
        <br />
        <br />
        <asp:ValidationSummary ShowMessageBox="true" ShowSummary="false" ID="ValidationSummary1" HeaderText="You must enter a value in the following fields:"
            DisplayMode="BulletList" EnableClientScript="true" runat="server" />
    </form>
</body>
</html>

Thursday, July 1, 2010

How to Check/Validate for empty value in asp.net | RequiredFieldValidator

RequiredFieldValidator is used to verify for empty values in check box. If entered value id empty you can not proceed and will prompt to enter a value.

 

How to Check/Validate for empty value in asp.net | RequiredFieldValidator

How to Check/Validate for empty value in asp.net | RequiredFieldValidator

 

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
<html>
<body>
    <form id="Form1" runat="server">
        <h4>
            Check for Require Field</h4>
        <br />
        Enter a value:
        <asp:TextBox ID="txtRequiredField" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" Text="Check" runat="server" />
        <br />
        <br />
        <asp:RequiredFieldValidator ID="MyRequiredFieldValidator" ControlToValidate="txtRequiredField"
             ErrorMessage="Please enter a value to proceed." runat="server" />
    </form>
</body>
</html>

Sponsored Ad

More Related Articles

Website Update

Followers