i'm making a .aspx page with a checkbox that when it was checked it have to change the visibility of a radio list.
When i check it, the radio list was shown but when i uncheck it, the radio list don't disappears.
So, my code is that:
Front-end:
<asp:CheckBox ID="ckbProspect" runat="server" AutoPostBack="true"
oncheckedchanged="ckbProspect_CheckedChanged" />
<asp:RadioButtonList ID="rbListProspect" runat="server" Visible="false"
AutoPostBack="true" RepeatDirection="Horizontal">
<asp:ListItem Value="1" Text="Sim"></asp:ListItem>
<asp:ListItem Value="0" Text="Não"></asp:ListItem>
</asp:RadioButtonList>
Back-end
protected void ckbProspect_CheckedChanged(object sender, EventArgs e)
{
rbListProspect.Visible = ckbProspect.Checked;
}
How can i fix that and what it's wrong?
Try this:
<asp:CheckBox ID="ckbProspect" runat="server" Checked="false"
OnCheckedChanged="ckbProspect_CheckedChanged" AutoPostBack="true"/>
P.S: I believe there's nothing wrong with your code, it's working just fine.
Related
Example:
<asp:DropDownList runat="server" AutoPostBack="true" ID="ddlSample">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
Now if change the item in the above dropdown it will cause all the other dropdowns postback events to fire.
Like
<asp:DropDownList EnableViewState="true" ID="ddlNewSelec" runat="server"
AutoPostBack="true" OnSelectedIndexChanged="ddlNewSelec_SelectedIndexChanged">
<asp:ListItem Text="--Select Test Type--" Value="" />
</asp:DropDownList>
Details:
The Page has ViewState disabled. I try enabling viewstate for the individual dropdowns but it does not matter.
Any idea why this is happeing.
Let me know if you need any more details
EDIT:
The dropdown fires the selectedindexchanged event of all other dropdowns on the form. The dropdown named as ddlSample is doing nothing just causing postback but why the selectedindexchanged evenet of other dropdowns fired up.
Additional Info:
All the inputs are in updatePanel and removing them does not make any effect.
In Page Load i am not doing anything on postback
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindSomeDDLs();
}
}
You didn't bind the SelectedIndexChanged event on the "ddlSample" dropdown. Please try binding that property like so..
<asp:DropDownList ID="ddlSample" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlSample_SelectedIndexChanged">
<asp:ListItem Text="text1" />
<asp:ListItem Text="text2" />
</asp:DropDownList>
The answer seems to be very weird but this is true.
This is happening just because of EnableViewState property set to false.
I've created two radio buttons with the following code:
<telerik:RadButton ID="rbOption1" runat="server" Text="option 1" ToggleType="Radio"
GroupName="group1" ButtonType="ToggleButton" />
<br />
<telerik:RadButton ID="rbOption2" runat="server" ToggleType="Radio"
GroupName="group1" ButtonType="ToggleButton">
<ContentTemplate>
<asp:Label ID="lblChoose" runat="server" Text="choose" />
<asp:DropDownList ID="ddlChoose" runat="server" />
</ContentTemplate>
</telerik:RadButton>
I want the second radbutton to be rendered with a radio button just the the first radbutton. But instead the entire contents of the content template is being rendered as an html anchor and no radio button is being shown for the second radbutton. Is there a way to use the telerik radbutton to look like this mockup?
When the content of a RadButton is specified through the ContentTemplate inner property, the button control is automatically configured in a LinkButton mode.
The desired functionality can be achieved via two RadButtons, configured as radio buttons (ToggleType="Radio" ButtonType="ToggleButton"), and a DropDownList control that can be enabled only when one of the radio buttons is checked:
Page
<telerik:RadButton ID="rbOption1" runat="server" Text="option 1" ToggleType="Radio"
GroupName="group1" ButtonType="ToggleButton" />
<br />
<telerik:RadButton ID="rbOption2" runat="server" Text="choose" ToggleType="Radio"
GroupName="group1" ButtonType="ToggleButton" />
<asp:DropDownList ID="ddlChoose" runat="server" Enabled="false">
<asp:ListItem Text="Text" Value="Value"></asp:ListItem>
<asp:ListItem Text="Text" Value="Value"></asp:ListItem>
</asp:DropDownList>
<br />
Code-behind
protected void Page_Load(object sender, EventArgs e)
{
ddlChoose.Enabled = rbOption2.Checked;
}
I have got problem with FileUpload control. I have this one, two drop down list, text box and button. If I select in first dropDownList "Yes" second one become disable and set value on NO (In second ddl I have two option YES or NO and in first one as well) however if I select NO in first dropDownList I posible to choose both option in second dropDownList. First ddl change second one on postBack using selectedIndexChanged evet and when it happends I loose file name in UploadFile control which I set before.
Code sample:
<asp:FileUpload ID="fuUploadGeometry" runat="server" Width="100%" />
<asp:DropDownListID="ddlSymmetry"runat="server" AutoPostBack="true"
onselectedindexchanged="ddlSymmetry_SelectedIndexChanged">
<asp:ListItem Value="0">-- Select --</asp:ListItem>
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlModule" runat="server" Enabled="True">
<asp:ListItem Text="-- Select --" Value="0"/>
<asp:ListItem Text="Yes" Value="1" />
<asp:ListItem Text="No" Value="2"/>
</asp:DropDownList>
<asp:TextBox ID="txtTopic" runat="server"></asp:TextBox>
What should I do to keep file name in UploadFile control during changes selected options in drop down lists?
Try this, I added the label so you can see that the postback of the onselectedindexchange only affects the dropdown and not the file upload control, hope this helps.
<asp:FileUpload ID="fuUploadGeometry" runat="server" Width="100%" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlSymmetry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlSymmetry_SelectedIndexChanged">
<asp:ListItem Value="0">-- Select --</asp:ListItem>
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlModule" runat="server" Enabled="True">
<asp:ListItem Text="-- Select --" Value="0" />
<asp:ListItem Text="Yes" Value="1" />
<asp:ListItem Text="No" Value="2" />
</asp:DropDownList>
<asp:TextBox ID="txtTopic" runat="server"></asp:TextBox>
<asp:Label runat="server" ID="msgFromList" />
</ContentTemplate>
</asp:UpdatePanel>
protected void ddlSymmetry_SelectedIndexChanged(Object sender, EventArgs e)
{
msgFromList.Text = ddlSymmetry.SelectedItem.Value.ToString();
}
First thing keep in ur mind that is FileUpload Control Will became empty if any post back event occur on ur web page. So best solution is to put ur file upload control after all controll that can cause a post back like drop down list.
I have got a dropdown list populated with products from a product table. I have a button named ADD Product, so when the user wants to add a new product instead of selecting product from the drop down list, one should click on add new then panel 1 should show which includes a textbox. Panel1 visibility is set to false by default and it should be visible when the user clicks on the button. Also I want a validation on dropdown list and textbox(if panel is visible). Below is the code which is not working :
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<%--<asp:TextBox ID="txtMake" runat="server" CssClass="txtStyle"></asp:TextBox>--%>
<asp:Button ID="btnAdd" runat="server" />
<asp:Panel ID="panel1" Visible="false" runat="server"><asp:TextBox ID="txtAddnew"></asp:TextBox></asp:Panel>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please Select a Product" ValidationGroup="insert" ControlToValidate="DropDownList1" ForeColor="Red"></asp:RequiredFieldValidator><br />
codebehind:
protected void btnAdd_Click(object sender, EventArgs e)
{
panel1.Visible = true;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
MultiView1.ActiveViewIndex = 0;
DropDownList1.DataSource = caravans.GetProductNames();
DropDownList1.DataBind();
}
}
You can use this concept for validation on dropdownlist. I am given you an example please check this...
<asp:DropDownList runat="server" ID="ddl">
<asp:ListItem Value="-1" Text="Select"></asp:ListItem>
<asp:ListItem Value="1" Text="One"></asp:ListItem>
<asp:ListItem Value="2" Text="Two"></asp:ListItem>
</asp:DropDownList>
<asp:RegularExpressionValidator ID="reg1" runat="server" ControlToValidate="ddl"
Display="Dynamic" ErrorMessage="Select Proper" SetFocusOnError="true" Text="Select Proper"
ValidationGroup="check" ValidationExpression="^\d{0,5}$" />
<asp:Button ID="btn" runat="server" ValidationGroup="check" Text="Submit" />
I have an ASP.NET RadioButtonList on my form and I would like to convert it so that it is a JQuery Button like this.
My simple code:
<asp:Label ID="lblOrderType" Text="Order Type" runat="server" CssClass="label" />
<asp:RadioButtonList ID="radOrderType" runat="server" RepeatDirection="Horizontal" CssClass="radioButtonList">
<asp:ListItem value="M" Selected="True">Market</asp:ListItem>
<asp:ListItem value="L">Limit</asp:ListItem>
<asp:ListItem value="S">Stop</asp:ListItem>
</asp:RadioButtonList>
<asp:Button
ID="btnInsert"
runat="server"
Text="Insert"
onclick="btnInsert_Click" CssClass="button"
/>
When the btnInsert button is clicked I want to retrieve the value of the selected radio button, but using a JQuery button.
protected void btnInsert_Click(object sender, EventArgs e)
{
// some database code
DB.Insert(radOrderType.SelectedValue);
}
How would I go about doing this?
Assuming you've already got a reference to the jquery and jquery-ui js files try adding this to your markup:
<script type="text/javascript">
$(document).ready(function() { $("#<%= radOrderType.ClientID %>").buttonset(); });
</script>