I am trying to style my quiz with checkbox/radio button lists controls in asp.net to match that of the bootstrap static variants found here: http://getbootstrap.com/javascript/#buttons-checkbox-radio
This works fine using the following lines of code:
<asp:RadioButtonList ID="rblQuestion1" runat="server" RepeatDirection="Vertical" RepeatLayout="Flow" CssClass="btn-group" data-toggle="buttons">
<asp:ListItem class="btn btn-default radio-inline" Value="1">Answer One</asp:ListItem>
<asp:ListItem class="btn btn-default radio-inline" Value="2">Answer Two</asp:ListItem>
</asp:RadioButtonList>
But i have three problems:
The items are rendered in steps like so: http://i.imgur.com/aM1A1Gh.png, I believe the cause to be the "RepeatLayout=Flow" property, but without this element isn't displayed as shown on the bootstrap website http://getbootstrap.com/javascript/#buttons-checkbox-radio
When displayed on a smaller screen, some of the items do not fit as the text within them is quite long, what would be the best way to fix this? Image: http://imgur.com/OpCSbLD
and lastly:
After the form is submitted, it postbacks to the page disabling the control via VB code, and highlighting the correct answer. However, this removes the element styling
This is the HTML displayed when taken from the browser:
<span id="ContentMain_wizQuestions_rblQuestion1" disabled="disabled" class="aspNetDisabled btn-group" data-toggle="buttons">
<span class="aspNetDisabled">
<input id="ContentMain_wizQuestions_rblQuestion1_0" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="1" disabled="disabled"><label for="ContentMain_wizQuestions_rblQuestion1_0">Answer One</label></span><br>
<span class="aspNetDisabled"><input id="ContentMain_wizQuestions_rblQuestion1_1" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="2" disabled="disabled">
<label for="ContentMain_wizQuestions_rblQuestion1_1">Answer Two</label></span><br>
<span class="aspNetDisabled"><input id="ContentMain_wizQuestions_rblQuestion1_2" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="3" checked="checked" disabled="disabled">
<label for="ContentMain_wizQuestions_rblQuestion1_2">Answer Three</label></span><br>
<span class="aspNetDisabled"><input id="ContentMain_wizQuestions_rblQuestion1_3" type="radio" name="ctl00$ContentMain$wizQuestions$rblQuestion1" value="4" disabled="disabled">
<label for="ContentMain_wizQuestions_rblQuestion1_3">Answer Four</label>
</span>
I believe the aspNetDisabled span tag, is interferring with the bootstrap styles. How can i make them persist through this, or is there an alternative better way to disable an element?
Thanks
Read the following MSDN document
That is because of controlRenderingCompatibilityVersion. If your framework version is above 4, then this property will be set default to "pages controlRenderingCompatibilityVersion="4.0"
Change the controlRenderingCompatibilityVersion="3.5" and you can see class="aspNetDisabled" will be removed from html.
Web Control facility after .NET version 3.5
Method 1 :
please add following in your web.config for remove the aspNetDisabled tag
<system.web>
<pages enableEventValidation="true" controlRenderingCompatibilityVersion="3.5" />
</system.web>
Method 2 :
you can also ended up doing the following, which effectively removes the insertion of the extra class for disabled items.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
WebControl.DisabledCssClass = "";
}
Related
I need to remove this span tag its come automatically when i click on radio button
I think you used class="with-gap" in <input> like this :
<input class="with-gap" name="group3" type="radio" checked />
Remove it like this :
<input name="group3" type="radio" checked />
And your problem will be solve. Read here for more info.
In my asp.net website I have created a user control called GlobalHeader.ascx to make header content consistent throughout the website and put a text box control for search functionality as given below:
<div style="display:none;">
<form id="sample"></form>
</div>
<div>
<form id="cse-search-box" name="cse-search-box" method="get" action="/Search Results.aspx">
<input type="hidden" name="cof" value="FORID:11;NB:1" />
<input type="text" name="q" id="q" class="search-txt" onfocus="if(this.value=='Search')this.value='';" onblur="if(this.value=='')this.value='Search';" value="Search"/>
<input type="submit" name="sa" value="Search" class="search-iocn" />
</form>
Now in child page I'm having a drop-down control having AutoPostBack=true and OnSelectedIndexChanged="DrpdwnListSelectedIndexChanged" i.e. on item change event DrpdwnListSelectedIndexChanged is fired and and show some data just under drop-down list. BUT this functionality is ONLY work when I remove search functionality from Header user control.
<asp:DropDownList runat="server" ID="drpdwnList" AutoPostBack="True" OnSelectedIndexChanged="DrpdwnListSelectedIndexChanged">
</asp:DropDownList>
This means form tag preventing drop-down list AutoPostBack functionality to work.
Why so?
How can I make both functionality work together?
Interesting thing is that If I remove <form id="sample"></form> from top search functionality doesn't work.
Thanks
I am trying to implement a toggle switch-toggle between textarea and ckeditor in my web form.
As of now I am able to toggle between the 2 editors.But I am not able to have the same contents in both the editors. Its treating it like 2 separate textarea, I want them to have the same contents when I toggle from textarea to ckeditor.Can anybody help me and lemme know what I am missing?
Thanks in advance
Code:
Updated code
<textarea id="editor1" name="editor1" class="ckeditor" rows="20" cols="75"></textarea>
<input type="button" value="CKEditor" onclick="CKEDITOR.replace('editor1');" />
<input type="button" value="Text editor" onclick="CKEDITOR.instances.editor1.destroy('editor1');" />
<input type="submit" value="Submit" />
</form>
Use CKEDITOR.instances.editor1.destroy() to restore it to a textarea and call CKEDITOR.replace('editor1') again when you want a CKEditor.
Remove the whole <div id="textarea"> because otherwise you will get unexpected results, you're using two textareas with the same id and name.
I'm having some real problems with a group of HTML Radiobuttons when I try to pass the selected values back and forth between JavaScript and ASP.NET.
<input type="radio" id="radio1" name="markerSel" value="1" checked=true />
<input type="radio" id="radio2" name="markerSel" value="2" />
<input type="radio" id="radio3" name="markerSel" value="3" />
To begin with, the form loads with these radiobuttons and a user selects a value and submits the ASP.NET form. To get the value of the selected option on the server-side I have tried;
string selVal = Request.Form["markerSel"];
//always returns "1", regardless of the selection made.
And also tried ASP.NET's FindControl method (recursively too), and I just get null.
I want to be able to set the value of this radiobutton group via JavaScript and Asp.NET and be able to read from both environments.
Any help would be appreciated.
Thanks
Is there a reason why you don't use ASP.NET radio buttons instead of <input type=radio />?
If you use
<asp:RadioButton id="radio1" runat="server" Checked="true" />
<asp:RadioButton id="radio2" runat="server" />
<asp:RadioButton id="radio3" runat="server" />
You will be able to access them server-side by doing this.radio1.Checked
If you want to access your elements via javascript, you can do a document.getElementById('radio1') and you will get the DOM element that way.
If you want to use jQuery, you can access the radio buttons with
$('#radio1')
If you want to test if the radio button is checked, you can use
if ($("#radio1").is(':checked')) {//...
hmmm... I would try changing the line to:
string selVal = Request.Form("markerSel");
Is there any way to set a CSS class on an input item in a radio button list? I'd like to reference these form values by class in jQuery.
Given an ASP.NET RadioButtonList with classes set on the ListItems:
<asp:RadioButtonList ID="RadioButtonList" runat="server">
<asp:ListItem class="myClass" Text="Yes" Value="1" />
<asp:ListItem class="myClass" Text="No" Value="0" />
</asp:RadioButtonList>
Will render as:
<span id="RadioButtonList" class="radioButtonListField myClass">
<span class="myClass">
<input id="RadioButtonList_0" type="radio" value="1"
name="RadioButtonList"/>
<label for="RadioButtonList_0">Yes</label>
</span>
<span class="myClass">
<input id="RadioButtonList_1" type="radio" value="0"
name="RadioButtonList"/>
<label for="RadioButtonList_1">No</label>
</span>
</span>
Unfortunately, the "myClass" class is added to the <span> that contains the radio button item, not the <input> itself. How could I get it to look like this instead:
<span id="RadioButtonList" class="radioButtonListField myClass">
<span>
<input id="RadioButtonList_0" class="myClass" type="radio" value="1"
name="RadioButtonList"/>
<label for="RadioButtonList_0">Yes</label>
</span>
<span>
<input id="RadioButtonList_1" class="myClass" type="radio" value="0"
name="RadioButtonList"/>
<label for="RadioButtonList_1">No</label>
</span>
</span>
(This does not even get into the issue of adding the classes to dynamically bound RadioButtonLists.)
Yes, RadioButtonList renders horrible HTML.
Anyway, it's still easy to get them from jQuery.
Try
$('span.myclass input:radio')
Above will get all the radio buttons inside the span with class 'myclass'.
An alternative you may want to try to do is change your CSS class to accomindate the Server Control Rendering.
So in your CSS instead of the following:
.myClass { ... }
You Use this:
.myClass input { ... }
I don't know if you can set the class attribute (via class or CSSClass) in a declarative manner; however, the above should give you a work around.
untested
$('.myclass input:radio').each(function() {
this.css({'style-name':'style-value'})
)};
once the list is rendered, you can possibly manipulate the css client side using the above statement.
Using .NET you could create an event handler to the RowBinding event. This would allow you to access the individual controls within each item in the list. Once you pull the RadioButton control, you could programaticaly set it's CssClass to apply your class on the RadioButton level.
You could also use jquery to find the radio button controls that have myClass applied, and then apply another class to that.
Third, you could just change the definition of MyClass to also specify that it's only applied to input elements under elements that have MyClass applied.
the desigeek response is pretty good..
To get this to work for radiobuttons I had to do this on document.ready()
$('#<%=radRisksMarginTrading.ClientID %>_0').addClass("validate[required]");
$('#<%=radRisksMarginTrading.ClientID %>_1').addClass("validate[required]");
I'm sure there is a much better way to do it by looping but I need a quick fix for 5 radiobutton lists..