I have a radiobuttonlist on whose change event I want to change the watermark text in a textbox.
But I am not able to call Javascript function from RadioButtonList and also not able to retrieve the value of the selected field.
Below is the code for the same.
<asp:RadioButtonList ID="rdbSelectType" runat="server" CssClass="radioButtonList" RepeatDirection="Horizontal" AutoPostBack="true" OnSelectedIndexChanged="rdbSelectType_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="0" Text="Auto Generate"></asp:ListItem>
<asp:ListItem Value="1" Text="Manually Generate"></asp:ListItem>
</asp:RadioButtonList>
Can anyone help me on this please?
Related
I am trying to tranfer dropdown data to listbox using javascript and below is my asp.net CascadingDropDown drop-down control and filling drop down using Webservice
<asp:DropDownList ID="ddl_Trainer" runat="server" required="required" CssClass="form-control" AppendDataBoundItems="true">
<asp:ListItem Text="Select Trainer" Value=""></asp:ListItem>
</asp:DropDownList>
<cc1:CascadingDropDown ID="CascadingDropDown7" runat="server" Category="subproduct"
Enabled="True" LoadingText="Loading Trainer..." ParentControlID="ddl_ProjectType" PromptText="
- Select Trainer -"
ServiceMethod="GetDropDowntrainer" ServicePath="Getdropdowns.asmx"
TargetControlID="ddl_Trainer"></cc1:CascadingDropDown>
I want same data of dropdown into listbox control using Javascript, why i should write another webservice and below listbox control
<asp:ListBox ID="lst_OtherTrainers" runat="server" SelectionMode="Multiple" CssClass="form-control">
</asp:ListBox>
I know it has been asked several times and I found many solutions but no solution worked for me.
I am working on IE
<asp:RadioButtonList ID="rbtnView" runat="server" OnSelectedIndexChanged="rbtnView_SelectedIndexChanged"
AutoPostBack="True" TabIndex="7" RepeatDirection="Horizontal">
<asp:ListItem Selected="True" Value="0">Show Pending</asp:ListItem>
<asp:ListItem Value="1">Show Processed</asp:ListItem>
</asp:RadioButtonList>
here is the button code from where I am calling the function:
<asp:Button ID="btnPrint" runat="server" CssClass="myButton" OnClick="btnPrint_Click"
Text="Print" ValidationGroup="validationgroup2" TabIndex="9" OnClientClick="doPrint()" />
here is the javascrit function
function doPrint() {
debugger;
var rad = $('#<%=rbtnView.ClientID %> input[type=radio]:checked').val();
}
Any help would be appreciated.
var radioValue = $("input[name='YOURVALUEFORTHEGROUP']:checked").val();
replace YOURVALUEFORTHEGROUP
The javascript function works just fine. But you are doing a form post (PostBack) when pressing the btnPrint button.
You can use a regular button instead of an asp.net Control. Or if you need a PostBack to execute the btnPrint_Click method. But then you can get the value there. It all depends why you need the value client side.
<input type="button" value="Get value" onclick="doPrint()" />
Or add return false to the aspnet button.
OnClientClick="doPrint(); return false;"
I am needing to call a javascript function when my asp:ListBox has a selection change rather then running some server side code. What I have at the moment is.
<asp:ListBox ID="lbCustomerFolders" runat="server" Width="100%" Height="98%" AutoPostBack="true" OnSelectedIndexChanged="lbCustromerFolders_SelectedIndexChanged"/>
Where the OnSelectedIndexChanged I require that function or something similar to call a javascript function.
Add on change event in your control lie I have added in following example. Notice that there are onchange as well as OnSelectedIndexChanged event there on the ListBox so on the selection change event both JavaScript and server side event is going to get called.
In your case change would be data which you are providing.
<asp:ListBox ID="lbCustomerFolders" runat="server" Width="9%" Height="98%" onchange="YourChangeEventJS(this)" AutoPostBack="true" OnSelectedIndexChanged="lbCustomerFolders_SelectedIndexChanged">
<asp:ListItem Text="Red" Value="#FF0000" Selected="True" />
<asp:ListItem Text="Blue" Value="#0000FF" />
<asp:ListItem Text="Green" Value="#008000" />
</asp:ListBox>
Following is script should be there on your page
<script type="text/javascript">
function YourChangeEventJS(ddl) {
alert(ddl.selectedIndex);
}
How to get the selected items values of checkBoxList in button click event in jquery...
<asp:CheckBoxList ID="check_list" runat="server">
<asp:ListItem Text ="One" Value="1"></asp:ListItem>
<asp:ListItem Text ="Two" Value="2"></asp:ListItem>
<asp:ListItem Text ="Three" Value="3"></asp:ListItem>
</asp:CheckBoxList>
<input type="button" id="btn_click" value="Click"/>
just use an attribute selector like
On click of button you can loop trough all checked values like
$("#btn_click").click(function(){
$("[id*=check_list] input[type=checkbox]:checked").each(function () {
// add $(this).val() to your array
});
});
See the jQuery :checked selector as described in the API.
I have a dropdown list whose value is changed based on other controls in the UI using javascript.
I used the following code to change the dropdown list,
document.getElementById("ddlchkStsID").options[2].selected = true;
document.getElementById("ddlchkStsID").value = "3";
But in the code-behind, the ddlchkStsID.SelectedValue is still coming as first option's value.
This the control in aspx page.
<asp:DropDownList ID="ddlchkStsID" runat="server" TabIndex="10" CssClass="meta">
<asp:ListItem Text="TBD" Value="1" />
<asp:ListItem Text="Yes" Value="2" />
<asp:ListItem Text="No" Value="3" />
</asp:DropDownList>
Could someone help me how to get the changed value in the code-behind.
thanks in advance :)
Since the control is running at the server, you should be referencing the control using the ClientID, like this:
document.getElementById("<%=ddlchkStsID.ClientID%>").options[2].selected = true;
Is your JavaScript code actually working?