Solved

Modify control's Enabled property without postback?

Posted on 2010-11-10
2
519 Views
Last Modified: 2012-05-10
I have within the EmptyDataTemplate of a GridView a RadioButtonList, a DropDownList and a DetailsView control. I would like, based on which of the two values of the RBL is selected, for the DDL or DV control's Enabled property to change to true/false. I've accomplished this thru the following code-behind in the RBL's SelectedIndexChanged command but this requires AutoPostBack which causes the user to lose their place on the page as the page reloads scrolled to the top etc. It's not very elegant :( Is there a better way?

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadioButtonList rbl = (RadioButtonList)sender;
            DropDownList ddl = (DropDownList)(rbl.NamingContainer.FindControl("DropDownList1"));
            DetailsView dv = (DetailsView)(rbl.NamingContainer.FindControl("DetailsView1"));

            if (rbl.SelectedValue == "1")
            {
                ddl.Enabled = true;
                dv.Enabled = false;
            }
            else
            {
                ddl.Enabled = false;
                dv.Enabled = true;
            }        
        }
0
Comment
Question by:alright
2 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 63 total points
ID: 34105319
Place your GV inside UpdatePanel i.e. use of Asp.net AJAX.
http://msdn.microsoft.com/en-us/library/bb386454.aspx
0
 
LVL 10

Assisted Solution

by:P1ST0LPETE
P1ST0LPETE earned 62 total points
ID: 34105373
Use JavaScript.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>

<!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>
    <script type="text/javascript">
        function RadioButtonList1_SelectedIndexChanged(radioList)
        {
            var radioButtons = document.getElementsByName(radioList.id);
            if (radioButtons[0].checked) {
                document.getElementById('myDDL').disabled = false;
                document.getElementById('myDV').disabled = true;
            }
            else {
                document.getElementById('myDDL').disabled = true;
                document.getElementById('myDV').disabled = false;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:RadioButtonList ID="radioList" runat="server" onclick="RadioButtonList1_SelectedIndexChanged(this)">
            <asp:ListItem Text="EnableDDL" />
            <asp:ListItem Text="EnableDV" />
        </asp:RadioButtonList>
        <asp:DropDownList ID="myDDL" runat="server">
            <asp:ListItem Text="Item1" />
            <asp:ListItem Text="Item2" />
            <asp:ListItem Text="Item3" />
        </asp:DropDownList>
        <asp:DetailsView ID="myDV" runat="server" />
    </div>
    </form>
</body>
</html>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Polygon I google maps 1 16
Close form "before" open 3 30
designing in object programming 12 52
VB.NET (2008) - Refactoring Question 2 0
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now