I have created a simple radiobuttonlist. And I wrote simple function to do something on selection
here is the radiobuttonlist
<asp:RadioButtonList ID="payment_type" CssClass="rbl_type" runat="server" TextAlign="Right" RepeatDirection="Horizontal" BorderStyle="None" OnSelectedIndexChanged="payment_type_SelectedIndexChanged">
<asp:ListItem Value="0">Serbest Ödeme</asp:ListItem>
<asp:ListItem Value="1">Ön Tanımlı Ödeme</asp:ListItem>
</asp:RadioButtonList>
here is the c# code
protected void payment_type_SelectedIndexChanged(object sender, EventArgs e)
{
if (payment_type.SelectedValue == "0")
{
pnl_serbest.Visible = true;
pnl_on_tanimli.Visible = false;
}
else
{
pnl_serbest.Visible = false;
pnl_on_tanimli.Visible = true;
}
}
but it doesnt trigger anything. what am I doing wrong?
Add
AutoPostBack="true"
attribute to your <asp:RadioButtonList /> tag.
Related
I should disable all the radio buttons belonging to a group
I have an asp.net page containing several checks. I should make sure that depending on the option selected inside a listbox, a certain group of radio buttons will be hide or disabled.
<asp:DropDownList ID="modelTypeSelectIN" runat="server" AutoPostBack="true" OnSelectedIndexChanged="modelTypeSelect_SelectedIndexChanged">
<asp:ListItem Value="" Selected="True"> SELEZIONA IL TIPO DI FINITURA</asp:ListItem>
<asp:ListItem Value="air_IN">AIR</asp:ListItem>
<asp:ListItem Value="wide_IN">WIDE</asp:ListItem>
<asp:ListItem Value="sound_IN">SOUND</asp:ListItem>
<asp:ListItem Value="wave_IN">WAVE</asp:ListItem>
<asp:ListItem Value="box_IN">BOX</asp:ListItem>
<asp:ListItem Value="plana_IN">PLANA</asp:ListItem>
<asp:ListItem Value="planaFG_IN">PLANA FULL GLASS</asp:ListItem>
</asp:DropDownList>
<div class="box" runat="server" id="BoxProva"><asp:RadioButton ID="sup3" GroupName="Superfici" runat="server" AutoPostBack="true" /><span><span class="img" runat="server"><img src="~/In/Superfici/AIR_SLIGHTGRAIN/AIR SLIGHTGRAIN_8016_IN LUCE.png" alt="" runat="server"></span>PROVA DI FILTRO</span><div class="image-box"><img src="~/In/Superfici/AIR_SLIGHTGRAIN/AIR SLIGHTGRAIN_8016_IN LUCE.png" alt="" runat="server"></div></div>
<div class="box" runat="server" id="BoxProva"><asp:RadioButton ID="sup4" GroupName="Superfici" runat="server" AutoPostBack="true" /><span><span class="img" runat="server"><img src="~/In/Superfici/AIR_SLIGHTGRAIN/AIR SLIGHTGRAIN_8017_IN LUCE.png" alt="" runat="server"></span>PROVA DI FILTRO</span><div class="image-box"><img src="~/In/Superfici/AIR_SLIGHTGRAIN/AIR SLIGHTGRAIN_8017_IN LUCE.png" alt="" runat="server"></div></div>
This is a event handler:
protected void SlightGrain7016InLuce_CheckedChanged(object sender,
EventArgs e)
{
if (SlightGrain7016InLuce.Checked)
{
BoxProva.Visible = false;
}
}
something like this will work , use function to managed your radio button group ...
// Thsi will trigger When Dropdownlist selected option changed
protected void modelTypeSelect_SelectedIndexChanged(object sender, EventArgs e)
{
if (modelTypeSelectIN.SelectedItem.Text == "WIDE")
{
Disable_GroupSuperfici_RaddioButton();
}
else
{
Enable_GroupSuperfici_RaddioButton();
}
}
// This function Enable particular group of button
private void Disable_GroupSuperfici_RaddioButton()
{
sup3.Enabled = false;
sup4.Enabled = false;
//RadioButton1.Enabled = false;
//RadioButton2.Enabled = false;
}
// This function disable particular group of button
private void Enable_GroupSuperfici_RaddioButton()
{
sup3.Enabled = true;
sup4.Enabled = true;
//RadioButton1.Enabled = true;
//RadioButton2.Enabled = true;
}
I am looking for this over the internet but I am not getting any suitable answers. Here is my problem:
I have a web user control which has the following three controls
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true"
CssClass="radioButton" RepeatDirection="Horizontal" RepeatLayout="Flow"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" >
<asp:ListItem Value="UET111">Use Existing</asp:ListItem>
<asp:ListItem Value="CNT111">Create New</asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID="DropDownList1" runat="server" >
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" C></asp:TextBox>
It's code behind
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Visible = false;
TextBox1.Visible = false;
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedItem.Value == "UET")
{
DropDownList1.Visible = true;
TextBox1.Visible = false;
}
else if (RadioButtonList1.SelectedItem.Value == "CNT")
{
DropDownList1.Visible = false;
TextBox1.Visible = true;
}
}
Now my question-
Actually I am using this web control 5 times on the same aspx page. The problem is I want to fill the dropdown list from aspx page and each dropdown will have different data(as I have 5 user control).
Is it possible to do that? Please help me with these and let me know if anyone knows a better way of doing this.
Create a public function in your user control that lets you send in a DataSource for the dropdown list to populate from, and if you want bind as well.
public BindDropdownDataSource(DataSet dataSource)
{
DropDownList1.DataSource = dataSource;
DropDownList1.DataBind();
}
I have a dropdownlist. I want whenever user selects India, it should go to the next section of the page and if it selects other than India, it should go to the some other section. And also it should only move ahead if the checkbox is checked, Otherwise it should ask to check the checkbox first. Please see the code for your reference:-
<asp:DropDownList ID="ddlCountry" runat="server" class="txtfld-popup" Width="251">
<asp:ListItem Text="Enter your Country of Residences" Value="0"></asp:ListItem>
<asp:ListItem Text="India" Value="1"></asp:ListItem>
<asp:ListItem Text="USA" Value="2"></asp:ListItem>
<asp:ListItem Text="Other" Value="3"></asp:ListItem>
</asp:DropDownList>
Also see the checkbox code:
<asp:CheckBox ID="checkcountry" runat="server" />
I confirm that I am a resident of the selected jurisdiction.
<div id="errordiv" runat="server" style="color: #cf060d; font-size: 12px;"></div>
Also, see the button code
<asp:Button ID="btnSend" runat="server" ValidationGroup="VG"
OnClick="btnSend_Click" Class="button-form" Width="65" />
On button click event
protected void btnSend_Click(object sender, EventArgs e)
{
if (!checkcountry.Checked)
{
errordiv.InnerHtml = "Please select the authorization checkbox to proceed.";
return;
}
if (Page.IsValid)
{
// Response.Redirect("LegalPopup1.aspx");
ClientScript.RegisterClientScriptBlock(this.GetType(), "ResponseDialog", "$(document).ready(function(){ResponseDialog();});", true);
}
}
Add AutoPostBack as true for the DropDownList and add selected index changed event like below
<asp:DropDownList ID="ddlCountry" runat="server" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" AutoPostBack="true"
inside your "ddlCountry_SelectedIndexChanged" code, you can check the selected values, checkbox values and do whatever you want based on those values.
Code
protected void btnSend_Click(object sender, EventArgs e)
{
if (checkcountry.Checked == true)
{
if (checkcountry.Checked == true && ddlCountry.SelectedIndex != 0 && ddlCountry.SelectedItem.Text == "India")
{
divForInida.Visible = true;
divForOther.Visible = false;
}
else if (checkcountry.Checked == true && ddlCountry.SelectedIndex != 0 && ddlCountry.SelectedItem.Text != "India")
{
divForInida.Visible = false;
divForOther.Visible = true;
}
else
{
//message for `Select a country of residence`
}
}
else
{
//message for `check the checkbox`
}
}
<asp:DropDownList ID="ddlCountry" runat="server" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" AutoPostBack="true" >
And Your selected index changed event will look like this
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(ddlCountry.SelectedItem.Text))
{
if (ddlCountry.SelectedItem.Text == "India")
{
}
else
{
}
}
}
catch (System.Exception ex)
{
throw new MyException(" Message:" + ex.Message, ex.InnerException);
}
}
The following code produces a null reference error on this line href.NavigateUrl = "foo.aspx?id=" + id; when I change the DropDownList selection, but not when I enter the id as a QueryString parameter. It seems like it has something to do with the order of events, but I'm not sure what, or how to fix it.
.aspx
<asp:Panel ID="Panel1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<br />
<asp:Panel ID="Panel2" runat="server" Visible="false">
<asp:LoginView ID="LoginView1" runat="server">
<RoleGroups>
<asp:RoleGroup Roles="superadmin">
<ContentTemplate>
<asp:HyperLink runat="server" ID="HyperLink1">HyperLink</asp:HyperLink>
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
</asp:LoginView>
</asp:Panel>
.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["id"] != null)
{
if (!String.IsNullOrEmpty(Request.QueryString["id"]))
{
Panel1.Visible = false;
SetHref(Request.QueryString["id"]);
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SetHref(DropDownList1.SelectedValue);
}
protected void SetHref(string id)
{
Panel2.Visible = true;
HyperLink href = (HyperLink)LoginView1.FindControl("HyperLink1");
href.NavigateUrl = "foo.aspx?id=" + id;
href.Text = href.NavigateUrl;
}
I've found a couple of work-arounds: setting the default visbility of Panel2 to true is one, and moving the HyperLink outside of Panel2 and changing its visibility directly is the other, but neither of those do exactly what I want because there are other controls that I am trying make visible/invisible along with the HyperLink.
Any thoughts?
Instead of using the following line:
Panel2.Visible = true;
Try using:
Panel2.Attributes["style"] = "display:none";
I think the contents of your panel might not be rendering when you set Visible to false.
I'm basically trying to bind the dropdown list with the radio buttons. there are 4 options in the dropdown menu according to which the radio buttons should be selected.
with the first two options, the radio buttons should be active and with the rest of two objects in the dropdown menu, the radio buttons should become inactive.
here is my front end code for dropdown:
<asp:DropDownList ID="ddLType" runat="server" Width="406px" Height="23px">
<asp:ListItem Value="Prof">Professional</asp:ListItem>
<asp:ListItem>Enterprise</asp:ListItem>
<asp:ListItem>Maintanence</asp:ListItem>
<asp:ListItem>Reporting</asp:ListItem>
</asp:DropDownList>
here is my code for radio buttons:
<asp:RadioButtonList ID="rdoMeapSupport" RepeatDirection="Horizontal" runat="server" AutoPostBack="True" >
<asp:ListItem Value="1" Text="Yes" />
<asp:ListItem Value="0" Text="No" />
</asp:RadioButtonList>
if we select professional, the radio buttons should be active with yes as the checked option.
with enterprise, both the buttons should be active but not selected.
with maintenance and reporting, the buttons should become inactive.
First of all you have to set the property of drop down list called AutoPostBack to true. You can do this by simply selecting your drop down list and set AutoPostBack = true from properties window.
Then go to code behind file write these codes:
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if (ddLType.SelectedValue == "Professional")
{
rdoMeapSupport.Enabled = true;
rdoMeapSupport.SelectedValue = "Yes";
}
}
}
after that set event for your radio button list "SelectedIndexChanged"
and paste this code inside that
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddLType.SelectedValue == "Professional")
{
rdoMeapSupport.Enabled = true;
rdoMeapSupport.SelectedValue = "Yes";
}
if (ddLType.SelectedValue == "Enterprise")
{
rdoMeapSupport.SelectedValue = null;
rdoMeapSupport.Enabled = true;
}
if ((ddLType.SelectedValue == "Maintanence") || (ddLType.SelectedValue == "Reporting"))
{
rdoMeapSupport.SelectedValue = null;
rdoMeapSupport.Enabled = false;
}
}
Apply AutoPostBack="true" attribute to the dropdown and do the below logic in the selected index change event.
<asp:DropDownList ID="ddLType" runat="server" Width="406px" Height="23px"
onselectedindexchanged="ddLType_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Value="Prof">Professional</asp:ListItem>
<asp:ListItem>Enterprise</asp:ListItem>
<asp:ListItem>Maintanence</asp:ListItem>
<asp:ListItem>Reporting</asp:ListItem>
</asp:DropDownList>
<asp:RadioButtonList ID="rdoMeapSupport" RepeatDirection="Horizontal" runat="server"
AutoPostBack="True">
<asp:ListItem Value="1" Text="Yes" />
<asp:ListItem Value="0" Text="No" />
</asp:RadioButtonList>
protected void ddLType_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddLType.SelectedIndex == 0 || ddLType.SelectedIndex == 1)
{
rdoMeapSupport.Enabled = true;
}
else
{ rdoMeapSupport.Enabled = false; }
}
I think making radio buttons active, but not allowing to select is none of use, better you disable it.
You may use jquery for this:
<script>
$(function () {
$("# <%# ddLType.ClientID %>").change(function () {
var selVal = $(this).val();
if(selVal == "Prof"){
$('#rb_Statusno').removeAttr('disabled');
else
$('#rb_Statusno').attr('disabled', true);
}
</script>
For more help you may go through this post.