Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Modify control's Enabled property without postback?

Posted on 2010-11-10
2
Medium Priority
?
524 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 252 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 248 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…

670 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