Solved

Modify control's Enabled property without postback?

Posted on 2010-11-10
2
523 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

636 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