Making Checkboxlist invisible - asp.net

I have a checkboxlist in ASP.net with several choices in it. Is there a way that I can make the physical check able box invisible? I want it so that only the item in question is visible, but the box is invisible. If this is not possible can somebody recommend an alternate ASP control that would behave similarly to the checkboxlist?
For example I have a checkboxlist such as this:
<asp:CheckBoxList ID="Example" runat="server" AutoPostBack="false" RepeatColumns="2" RepeatDirection="Horizontal">
<asp:ListItem> 1 </asp:ListItem>
<asp:ListItem> 2 </asp:ListItem>
<asp:ListItem> 3 </asp:ListItem>
<asp:ListItem> 4 </asp:ListItem>
<asp:ListItem> 5 </asp:ListItem>
</asp:CheckBoxList>
Now I want only the number to be visible and selectable, but I want to the checkbox to be invisible. Much like the way a button works but I feel as though creating x amount of buttons may be more tedious.
As per the answer I have tried the demo Jquery and came out with this:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Testjq.Test" %>
<!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">
<script type = "text/javascript" src ="Scripts/jquery-1.7.1.min.js"></script>
<script type = "text/javascript" src ="Scripts/jquery-ui-1.8.18.custom.min.js"></script>
<script>
$(function () {
$("#check").button();
$("#format").buttonset();
});
</script>
<style>
#format { margin-top: 2em; }
</style>
<title></title>
</head>
<body>
<div class="demo">
<input type="checkbox" id="check" /><label for="check">Toggle</label>
<div id="format">
<input type="checkbox" id="check1" /><label for="check1">B</label>
<input type="checkbox" id="check2" /><label for="check2">I</label>
<input type="checkbox" id="check3" /><label for="check3">U</label>
</div>
</div><!-- End demo -->
</body>
</html>
Unfortunatley I still cannot get it to work. Any additional help would be much appreciated.

Did you check the jQueryUI?
Take a look at the demo page: http://jqueryui.com/demos/button/#checkbox
If I understood well they have exactly what you are looking for.

Related

CSS in an external file not being applied

I've read some similar issues here, but no answer they provided could help me.
I have a small asp.net page for study porpuses:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="Site.Default" %>
<!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></title>
<link rel="Stylesheet" type="text/css" href="/css/Landing.css" />
</head>
<body>
<form id="form1" runat="server">
<div id="loginHeader" class="aaa">
<div>
<asp:TextBox ID="txtUsername" runat="server"/>
<asp:TextBox ID="txtPassword" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="Login" OnClick="btnLogin_Click" />
<asp:Button ID="Button2" runat="server" Text="Register" OnClick="btnRegister_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="Password not valid" Visible="False"/>
</div>
</div>
</form>
</body>
</html>
As you can see, the css/landing CSS file is being added.
Here is this css file:
#loginHeader
{
display:block;
background-color:Blue;
}
.aaa
{
display:block;
background-color:Red;
}
If I open the page, no style is applied. Firebug shows that the css is being downloaded.
If I move the css markup to the page, inside a tag, it works, if I change back to the css file, it stops working.
Do you see any reason for this behavior?
Thanks,
Oscar
I Just found it out: there was an error on my config file, which defined that the user should be logged in to access the css files...
solved, thanks :)
You have written the link tag this way.
<link rel="Stylesheet" type="text/css" href="/css/Landing.css" />
Make it
<link rel="Stylesheet" type="text/css" href="css/Landing.css" />
This will instruct the browser to look for the "Landing.css" file inside the css directory.

Why is a postback not being triggered?

I have a simple web form, but when I submit the button postback is always false. This should all happen on the same page.
<form runat="server" class="frm" method="post" action="">
<span><input type="radio" name="options" value="Milk" /><label>Option 1</label></span>
<span><input type="radio" name="options" value="Butter" /><label>Option 2</label></span>
<span><input type="radio" name="options" value="Cheese" /><label>Option 3</label></span>
<span><input type="radio" name="options" value="Milk" /><label>Option 4</label></span>
<span><input type="radio" name="options" value="Butter" /><label>Option 5</label></span>
<span><input type="radio" name="options" value="Cheese" /><label>Option 6</label></span>
<input type="submit" name="submit" value="vote" />
</form>
*Button Code *
<asp:Button ID="loginBtn" runat="server" Text="vote" OnClick="Login" />
As Noon Silk said, you need to use server side controls, but you also need to use the asp.net mechanism on the form tag; see example code below. Notice the form tag has a 'runat="server"' attribute rather than a method and action:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="button" runat="server" />
</div>
</form>
</body>
</html>
Because you're not using the .net controls; you are just doing it manually.
You'd need to use an ASP.NET button, like so:
<asp:Button runat="server" ID="btnSubmit" ... />
And same for your inputs, if you want to be able to access them through txtFoo.Text. Of course, if you don't, you can still access everything through Request[...].

disabled attribute not working

For some reason none of these DIVs render disabled. Oddly enough, when I set Enabled="False" on the .NET Panel, then it renders the Panel as a DIV with disabled="disabled", which works great.
Here's my doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<div id="Div1" disabled="disabled">
<input type="text" value="blah" />
</div>
<div id="disableMe" disabled="disabled">
<input type="text" value="blah" />
<asp:Panel runat="server">
<asp:RadioButtonList runat="server">
<asp:ListItem Text="Item1" Selected="True" />
<asp:ListItem Text="Item2" />
</asp:RadioButtonList>
<asp:TextBox runat="server" Text="Hello World" />
</asp:Panel>
</div>
Disabled is not an attribute for a DIV, but an attribute for every form element (like INPUT, SELECT, TEXTAREA).
Just add the disabled attribute to ever form element within the DIV.
I guess the disabled="disabled" gets parsed server side and applies that status to children fields (runat="server"), because in html there's no disabled="disabled" for <div> elements.
You basically want to use CSS display: none here.
<div style="display: none;">
A <div> is a simple HTML element and get printed to HTTP response as-is, it's not some server side component which generates some HTML (like as those other ASP.NET components are doing).

How to apply CSS to a textbox?

I have this code, and it renders this HTML. How can I apply CSS to my control if they are named ctrctrctr-00000 or something else like that that is only useful to the VIEWSTATE?
<!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><title>
</title><link href="../global.css" rel="stylesheet" type="text/css" />
Informacion General: Paises
</head>
<body>
<form name="aspnetForm" method="post" action="Pais.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTUyMDk1NTY2MGRkwAKu2OIV85kXfcUcAefBBNmSuRY=" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLSha7NBAKqw7ARAvjQlaIKhJ2HMftmmOoxe/+aE4sG3D32QtA=" />
</div>
<div>
<input name="ctl00$ContentPlaceHolder1$txtPais" type="text" id="ctl00_ContentPlaceHolder1_txtPais" />
<input type="submit" name="ctl00$ContentPlaceHolder1$btnSubmit" value="Button" id="ctl00_ContentPlaceHolder1_btnSubmit" />
</div>
</form>
</body>
</html>
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Frontend._Default" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Prueba de Escritorio</h1>
<asp:TextBox ID="txtPais" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Guardar" onclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
How can I use a CSS selector to target ALL textboxes on the page regardless of name?
Thank you.
Why wouldn't you do this either:
input[type=text] { /* style */ } (standard)
or
input.text { /* style */ } (not as standard)
???
You can give it a CSS class, like this:
<asp:TextBox ID="txtPais" runat="server" CssClass="textbox" />
Then just use add what you need in your CSS:
.textbox { color: red; }
The CssClass property doesn't get mangled like the ID and name attributes.
you can use jQuery and do it like this:
$('input[id$=_txt]').addClass('yourClassName maybeAnotherClassName');
$(document).ready(function () {
$("input[type=text]").addClass("textBoxCSS");
}
For applying classes to text boxes on a page, you can further customize the selectors and be more specific.

Applying a Dojo Toolkit (Dijit) theme to ASP.NET pages

In the code below, I am trying to apply a Dijit theme to the controls in my .aspx page. However, the controls persist in their normal, unthemed appearance.
Anybody know why?
Master Page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Main.master.cs" Inherits="WebJournalEntryClient.Main" %>
<!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>My Web Application</title>
<link rel="stylesheet" href="dojoroot/dijit/themes/tundra/tundra.css" />
<script type="text/javascript" src="dojoroot/dojo/dojo.js"/>
<script type="text/javascript">
dojo.require("dijit.form.Button");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.ComboBox");
</script>
</head>
<body class = "tundra">
<form id="form1" runat="server">
<div>
<div>
This is potentially space for a header bar.
</div>
<table>
<tr>
<td>
Maybe <br /> a <br /> Side <br /> bar.
</td>
<td>
<asp:ContentPlaceHolder ID="CenterPlaceHolder" runat="server"/>
</td>
</tr>
</table>
<div>
This is potentially space for a footer bar.
</div>
</div>
</form>
</body>
</html>
Content Page:
<%# Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="LogIn.aspx.cs" Inherits="WebJournalEntryClient.LogIn" %>
<asp:Content ID="Content" ContentPlaceHolderID="CenterPlaceHolder" runat="server">
<div>
User ID: <asp:TextBox ID = "UserName" dojoType="dijit.form.TextBox" runat="server" /><br />
Password: <asp:TextBox ID = "PassWord" dojoType="dijit.form.TextBox" runat="server" /><br />
<asp:Button ID="LogInButton" Text="Log In" dojoType="dijit.form.Button" runat="server" />
</div>
</asp:Content>
You need to add djConfig="parseOnLoad: true" to you script tag.
<script type="text/javascript" src="dojoroot/dojo/dojo.js" djConfig="parseOnLoad: true"/>
Or
dojo.parser.parse();
Could be the path is wrong. Use Firebug to see if it's reading any css.
I am not sure about what ASP.net is doing with your page.
However in any case can you double check with firebug wheather your body has "tundra" class in the Browser Output ?? I am assuming that the CSS is comming properly (: as you mentioned in above comment)

Resources