How to get Radiobuttonlist inside of webusercontrol Selected Value using Javascript

Hello,

Can someone please help me with this? I can get the values if the list is not in a user control, but when it's in a web user control I can't.

I also have a masterpage.

  function geturl2() {
          var rdolist = document.getElementsByName('<%= ((RadioButtonList)wc1.FindControl("RadioButtonList1")).ClientID %>');
          if (rdolist[1].checked) {                                <<<<<< fails
              return rdolist[1].value;
          }
          else if (rdolist[2].checked) {
              return rdolist[2].value;
          }
          else if (rdolist[3].checked) {
              return rdolist[3].value;
          }
         
      }

Thank you!!! 

 

0
neo302
7/9/2008 3:43:08 PM
asp.net.client-side 24353 articles. 2 followers. Follow

11 Replies
1111 Views

Similar Articles

[PageSpeed] 50

Are you trying to do it in javascript on the client?  Is this for validation or something?  Explain what you're trying to do. Maybe there's a more direct approach.

Thanks.

Jason

0
Jas001
7/9/2008 4:10:24 PM

Hey,

I have a webusercontrol that is used on numerous forms. In this control is a radiobuttonlist. Depending on the selected listvalue, I need

to open a pop up window when the user clicks a submit button in the user control. I was going to store the URL as the selected value b/c

the URL to open in the pop up depends on what is selected in the control.

Thank you!!!

0
neo302
7/9/2008 4:21:56 PM

I can offer you a workaround.  If it drives you nuts and you just want to move on.  Have only one link for the popup go to a page.  This page will check the value of the radio button and can either redirect to the processing page or deal with the data.

Jason

0
Jas001
7/9/2008 4:31:36 PM

How is the JavaScript function geturl2 called, and what calls it?

NC...

 

0
NC01
7/9/2008 4:42:29 PM

Hey,

That sounds like it could work. Can you please show me how to do that?

Thanks!!!

0
neo302
7/9/2008 5:01:21 PM

geturl2 would be called by the button in the webusercontrol. When the user clicks this button, geturl2 would be called to return

the selected value of the radiobuttonlist in the user control. That Value would be used by javascript to open the popup window.

Thank you.

0
neo302
7/9/2008 6:13:42 PM

Change your JavaScript to this:

function geturl2(rdolistId)
{
 var rdolist = document.getElementsByName(rdolistId);
 if ( rdolist[1].checked )
 {
  return rdolist[1].value;
 }
 else if ( rdolist[2].checked )
 {
  return rdolist[2].value;
 }
 else if ( rdolist[3].checked )
 {
  return rdolist[3].value;
 }
}

And change the onclick event attachment to this in the UC:
Button1.Attributes.Add("onclick", "return geturl2('" + RadioButtonList1.ClientID + "');");

NC...

0
NC01
7/9/2008 6:55:18 PM

Hey NC01,

The problem is arising since the radiobuttonlist is in a WebUserControl, and the webUserControl has been placed on the page.

When I run it, it does not know what rdolist[1].checked is. I think the "checked" is causing it to mess up.

Do you know how to exposed the "checked" property or however it needs to be handled when the radiobuttonlist is in a webusercontrol?

 Thank you.

0
neo302
7/9/2008 7:25:05 PM

I see what the problem is now. The way that the IDs are mangled in version 2.0 is different than in 1.0/1.1, and that is causing an issue with the way that we are accessing the RadioButtons in the RadioButtonList.

Anyways, I have constructed a complete sample of the way to correct the problem for you.

WebUserControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>

<asp:RadioButtonList id="RadioButtonList1" runat="server">
 <asp:listitem value="1">Item 1</asp:listitem>
 <asp:listitem value="2">Item 2</asp:listitem>
 <asp:listitem value="3">Item 3</asp:listitem>
</asp:RadioButtonList>
<asp:button id="Button1" runat="server" text="Submit"></asp:button>

<script type="text/javascript">
<!--
function getRadioButtonListValue(radioButtonListId)
{
 var elementRef = document.getElementById(radioButtonListId);
 var inputItemArray = elementRef.getElementsByTagName('INPUT');
 var functionReturn = '';

 for (var i=0; i<inputItemArray.length; i++)
 {
  var inputItem = inputItemArray[i];

  if ( (inputItem.type == 'radio') && (inputItem.checked == true) )
  {
   functionReturn = inputItem.value;
   //alert(inputItem.value);
  }
 }

 return functionReturn;
}
function onButton1Click(radioButtonListId)
{
 var selectedValue = getRadioButtonListValue(radioButtonListId);

 if ( selectedValue.length <= 0 )
  alert('Please select an item.');
 else 
  alert(selectedValue);

 return (selectedValue.length <= 0) ? false : true;
}
// -->
</script>

WebUserControl.ascx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebUserControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
     this.Button1.Attributes.Add("onclick", "return onButton1Click('" + RadioButtonList1.ClientID + "');");
    }
}

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %>
<!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>Test Page</title>
 </head>
 <body>
  <form id="form1" runat="server">
   <uc1:WebUserControl ID="WebUserControl1" runat="server" />
  </form>
 </body>
</html>

NC...

0
NC01
7/10/2008 11:37:45 AM

It works awesome NC01!

Thank you for your help!!!!

0
neo302
7/10/2008 6:33:11 PM

Glad to be able to help. That should an idea of how to deal with User Controls. You just treat each UC like you would a page, placing the JavaScript into the ascx file, etc.

NC...

0
NC01
7/11/2008 11:25:04 AM
Reply:

Similar Artilces:

Get the Dropdownlist text and value using Javascript from client side
Hi, I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like: ( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. ) protected void Page_Load(object sender, EventArgs e) {              if (!Page.IsPostBack)            &nb...

Get RadioButtonList's selected value and index using Javascript
Hey,I cannot figure out the way to get the selected value of a radiobuttonlist. Here is the code: function PageIsFilleOut(i_name, limitt){        var temp = limitt - 1;        var check_text_area = new Boolean(false);        var index=1;                for (index = 1; index <= temp; index++)        {            var name_t =...

How to use client-side script(javascript) in DNA using .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script> objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ...... }   szUrl = "http://ServerNa...

how do i get selectedValue of drop down list server side if i am populating it using client side javascript?
 Hi All.I am populating a drop down list client side using: The drop down list is populated based on a selection of another drop down list. ddlList.options[i] = new Option(1,2); as an exampleThe populating is done as i need it to. However, a button click event i am trying to get the selectedValue of the ddlList. However, it doesn't give me it. It only gives me the selectedValue of the drop down list on first rendering. Any ideas on how i can get it?   Could You paste some code? That would be helpful. Thanks S@ss (Shashi Shekhar Singh)My BlogPlease mark a post as ANSWER ...

JavaScript to get Selected RadioButtonList value
Hi all,I want to know and ask you guys something.I have a radiobuttonlist and 2 normal radio buttons in my asp.net web page. And I use javascript to control the clicking of these controls. I already asked and found the way of using javascript to control normal radio button and it worked fine.But when i used these function to control the radionbuttonlist, it didn't seem to work well. (It worked but seems to have a little issue) My flow is when i click on radiobuttonlist (I have 3 listitem in these radiobuttonlist), i will get the selected value. So, i need to know which one is checked/sel...

get value selected Radiobuttonlist inside Datalist..
Dear all my experts <asp:DataList ID="DataList1" runat="server" DataKeyField="PollID" DataSourceID="SqlDataSource1" Width="100%" <ItemTemplate> <asp:RadioButtonList ID="rblOption" runat="server" DataSourceID="SqlDataSource2" DataTextField="OptionText" DataValueField="OptionID" RepeatDirection="Horizontal"> </asp:RadioButtonList> </ItemTemplate> </asp:DataList> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> When I click button1 I want to display the value of ...

How to use Client Side Scripting (Javascript) for RadioButtonLists?
Hi,  I have a two RadioButtonLists, rblParent and rblChild, each of which has has four radio buttons. All the buttons in rblChild are disabled at design time.   When the user selects an option in rblParent, I want to enable some of the radiobuttons in rblChild depending on the option selected by the User. I thought of using javascript, onClick event, but how do I do it for  <asp:RadioButtonList> controls? My aspx markup which fails when I build looks like this:   <asp:RadioButtonList ID="rblParent" runat="server" RepeatDirection=&quo...

Radiobutton list : Get selected Value using Javascript
for Some reason using OnSelectedIndexChanged didn't fire javascript event.  using Onclick did the magic.  Sample code: <asp:RadioButtonList ID="rblSample" runat="server"  OnClick="Update();"> <asp:ListItem Value="01">Text1</asp:ListItem> <asp:ListItem Value="02">Text2</asp:ListItem> <asp:ListItem Value="03">Text3</asp:ListItem> </asp:RadioButtonList></td> ----------------------------------------------- <script language ="javascript" ...

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on asp.net, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

How to use client-side script(javascript) in .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script>  objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ......  }    szUrl = &...

How to write data to a file in client side using javascript or someother client side scripting language.
Hi, I would like to know how to write a data to a client side file using javascript or someother client side scripting language. The file type expected is ini file. txt file would also be appreciable. Thanks in advance.   If the site is a trusted and you are running IE then you could try http://www.w3schools.com/asp/asp_ref_filesystem.asp The Old Sewing FactoryThat twitter nonsense. You can write to the server, but not to the client's machine.  Being able to do so would be a huge security breach.When you ask a question, remember to click "mark as answered"...

How to get the id of the selected node using client side script
Hello, How do I find out the id of the selected node using client side script? Thanks May be I wasn't clear enough. I have a tree view control that I render during run time. When the user clicks on a node (say after expanding several levels), I need to find out the ID of the node clicked. Is there a way I could find the selected node ID on the client side, without having to go to the server? view post 300589DNN skins ForumTressleworks modulesDNN & webhostingIEWCtrls...

How to get the selected text HREF value using vb.net
Hello friends,                     If i have a page opened in a web browser control for example www.google.com .if i select a particular content in google web page i have to get the href value of the selected text.how to do this vb.net.can anyone help me. with regards, Balaji.   Balaji,Chennai...

Client Side Selections Get Lost
Hello NG, I've got the following problem: I've got two ListBox Controls on my page. The left ListBox contains entries, which can be selected from the right ListBox by clicking on a button. This is realized on the clien side through Java Script. On every Postback, the prior selected items of the left ListBox, get lost. How can I make them persistent through Postbacks? Thanks for every hint! Cenk  My best regards,Cenk Add a hidden control to your form:     <input type="hidden" id="listBoxItems" name="listBoxItems" runat="server"> When you add an i...

Web resources about - How to get Radiobuttonlist inside of webusercontrol Selected Value using Javascript - asp.net.client-side

A2ZMenu tutorial index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Test Your Skill Q. Out of Boxing and ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 1 Jun 2012

DaniWeb Solved Articles - Technology Publication Meets Social Media
An online discussion community of IT professionals. Forums to get free computer help and support. We are a social technology publication covering ...

.NET sample code - developer Fusion
Discover the very latest .NET sample code Out of the box, the ASP.NET list controls (CheckBoxList, RadioButtonList, DropDownList) only support ...

ConditionalRequiredTextValidator Control
The ConditionalRequiredTextValidator control allows you to specify a CheckBox, RadioButton, CheckBoxList, RadioButtonList, DropDownList, or ListBox ...

ASP.NET 4 and Visual Studio 2010 Web Development Overview : The Official Microsoft ASP.NET Site
This document provides an overview of many of the new features for ASP.NET that are included in the.NET Framework 4 and in Visual Studio 2010. ...

Gaiaware - Gaia Ajax
Home Samples Download Free Trial Buy from $195 Login Download Free Trial ASP.NET Done Right 6 reasons to use Gaia Ajax? 40 UI controls 10 aspects/behaviors ...

A2ZMenu utilities index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Online Tool Title Description Rating ...

Online Exam papers index page
A2Zmenu.Com Blog Tutorials Online Exam Ask Question Utility Fun @ Work Funda Contact Us About Us Loading Test Your Skill Q. Out of Boxing and ...

A2ZMenu Experts Comment
A2ZMenu team is committed in providing solution in various technologies through blogs, tutorials, Q & A etc. Our objective is to give a knowledge ...

Resources last updated: 12/31/2015 2:21:44 PM