Check Box changes other check boxes

Hi, I have a question concerning changing a check box without doing a post back on the page. I would like to do something like this:

Public Sub checkAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkAll.CheckedChanged

If checkAll.Checked = False Then

   checkVisio.Checked =

True

   checkPPT.Checked =

True

   checkRawArt.Checked =

True

   checkFlatArt.Checked =

True

Else

   checkVisio.Checked =

False

   checkPPT.Checked =

False

   checkRawArt.Checked =

False

   checkFlatArt.Checked =

False

End If

End Sub

However, I would like the new "checks" to be added or removed without doing a post back. Do I have to use AJAX for something like this? If I would like to "fade" a check mark to grey, can I do that without reloading?

Thanks for your time,

James

0
JimmyFo
6/21/2006 5:59:05 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

5 Replies
736 Views

Similar Articles

[PageSpeed] 56

You could do that using Javascript...

In your VB code's Page_Load, say:
checkAll.Attributes.Add("onChange","CheckAll(this);")

Then in the code, put this javascript:

function CheckAll(obj) {
     var arrBoxes = new Array('Viso', 'PPT', 'RawArt', 'FlatArt');
     var chk;
     for (var i=0; i < arrBoxes.length; i++) {
           chk = document.getElementById('check' + arrBoxes[i]);
           if (chk) chk.checked = !obj.checked;
     }
}

Now there's a big "gotcha"-s too look out for
- That your checkbox controls have the actual id's "checkAll", "checkVisio", etc...   if these are inside pages that use master pages or inside other parnet controls, then the ID's would be different...  simply doing a "View Source" and visually inspecting the id property of the checkbox's will tell you if this is the case.. to which you'd then have to simply change the "document.getElementById" line above to have the common part of the name of all the boxes


"If you make it idiot proof, they'll build a better idiot"
0
MorningZ
6/21/2006 8:41:11 PM

Thanks - I have a question though.

It wasn't working, so I changed the

checkAll.Attributes.Add("onChange","CheckAll(this);")

to

checkAll.Attributes.Add("onCheckedChanged","CheckAll(this);")

It still isn't working, so I checked the ID under source, and it views like this:

http://i20.photobucket.com/albums/b231/JimmyFo/gp.jpg

Any ideas why it still isn't working? Even with a post back, it does not check.

Thanks,

James

0
JimmyFo
6/22/2006 6:49:20 PM

It's definitely "onChange"..

As for the ID, that's the server side ID, you need to find the ClientSide ID, which you can do by simply doing a "View Source" and go through the HTML to find one of the checkboxes


"If you make it idiot proof, they'll build a better idiot"
0
MorningZ
6/22/2006 9:26:03 PM

I did some rooting around and found that for this case, "onClick" is used instead of "onChange".

Do you know if there is a way to "fade" the check mark, i.e. if checkAll is checked and I uncheck one of the boxes, I'd like to use a similar JS function to "fade" the check mark.

Thanks,

James

0
JimmyFo
6/23/2006 3:46:02 PM

Quick question, why does it not do the same for a button?

Codebehind:

buttonSearch.Attributes.Add(

"onClick", "func_beginSearch(this);")

ASP:

function

func_beginSearch(obj) {

obj.Text =

'Searching...'

obj.Enabled =

false

}

It does not change the button. Ideas?

Thanks,

James

0
JimmyFo
6/28/2006 4:15:40 PM
Reply:

Similar Artilces:

Java script popup dialog box when a check box control is checked. How to do with a check box?
 I have a checkbox named cbxGetInfo. If someone checks the checkbox, I want to a popup dialog box confirming the action that will be done because of the checkbox being checked. A few months ago, I used a Java Script popup dialog box for a confirmation on an action being done. Now I need to figure out how to do this for when a check box has been checked. Can someone tell me what I am doing wrong. Here is the code I place in my C# code.    cbxGetInfo.Attributes.Add("onchecked", "javascript:if(confirm('Are you sure you want to delete this record?...

Checking Check Boxes
I've got a page that edits user permissions that I'm porting from PHP. When the page loads, I need the site to load a checkbox list with the name of the various items and the IDs as the value. This is easy. However, I also need it to check off the selected items. This information is stored in a seperate database table. Using a JOIN I can write a query that will return the page id, the page name, and the permissions of the user fairly easily. However, I don't know what attribute to set in order for appropriate boxes to be checked when the page loads. I'm posting this in the PHP m...

how to check if a check box created in runtime checked or not?
I have a webform that have mutiple collectios of check boxes created on run time ( database driven) what is the best way to loop between them and get which ones has been checked by a user and save the results back to the database below a portion of my code. i am adding the checkbox to cell table which added to a row, then to a table, finlally the table added to a place holderwhile (drProfileList.Read()) {HtmlTableRow tr = new HtmlTableRow(); HtmlTableCell tc = new HtmlTableCell();CheckBox chkbox = new CheckBox(); chkbox.ID = drProfileList["RoleID"].ToString();chkbox.T...

How to check how many check boxes are checked in the gridview
I am trying to make a javascript client fucntion to restrict no more then two rows could be selectedI have following in the itemtemplate of the gridview [although it is telerik control but same technique should be applied] <radG:GridTemplateColumn UniqueName="chkCheck">                    <HeaderStyle  HorizontalAlign="Right" />                    <HeaderTempla...

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

How to check for the existing user in database and using custom validator how to check check box is checked or not?
Hi Friends, For Registration page i want to check if that user already exist in database or not? and i also have to check if user have check the checkbox for i agree then only he will be able to complete registration. here i am sending my design. and all validation i have done all validation except these two.<html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PRIZE MLS</title><link href="css/style.c...

How to write event if check box get checked in datagrid
Some one tell me How to add check box to datagrid and write event for it, I want to have check box in my datagrid and want to write event if someone check raw in datagrid, How can I do this. help me on this maxmax thank you Hi, Do u want to add checkboxes to a column of a datagrid ? What do u want to do when check box is clicked ? (I mean u want something to happen for each click or u need to get the rows where the check boxes r clicked ?)   Hi:   You can try this:   <asp:DataGrid runat="server" ID="DataGrid1" DataSourceID="SqlDataSourc...

Details view text boxes
I have a details view set up for inserting. User A enters their details and User B enters their details. I have a check box so that when it is checked the details of both users is the same, i.e. I want the text from the User A text boxes to automatically fill the text boxes for User B. Does anyone know how to do this? Thanks....

Getting Started Check box inserts
Hello everyone  Im new to Asp.net and getting myway through an asp application. Im using a dataset to manage, data between my sql server database and my asp application but I have come across a problem that seems puzzling to me.  I have created an insert statement in my dataset as a dataadapter and importing it into the page i want to use. I want to insert a number of checkbox features as iether true or false into my database. However im unsure of how this is achieved and keep getting error messages.   This is my web page code.<%@ Page Language="vb" AutoEv...

how can i get the check boxes to be checked when the edit button is clicked
Hi, I have a datagrid which has update button to it... My datagrid consits of the following fields FundDefault Modelfund  FundName Cusip Ticker DisplayOrder Edit Remove Checkbox     chkbox    TxtBos                            Txtbox       basically all the details are coming from the database... Suppose the first row in my datagrid is as follow True   false   absnddkfd...

Get the datafield of check boxes that checked in datagrid(with java script)?
i have a datagrid that have some checkboxes. i introduce the check boxes in datagrid like: how can i get the datafield(like id) of check boxes that checked, from database(with java script) thanks. Why do you want do do it with javascript? It's not that easy ... You could just do it in code behind on a button click event. Then if you already have the id of the row in a column, you can fetch it like described in the following article: http://forums.asp.net/t/1131543.aspx If you have any comments, questions, remarks ... please let us know RegardsWimPlease remember to click ...

C# Putting a check in a check box if a text field is changed
I was wondering if someone can help me please. I am coding in C#. I would like to put a check in a check box field if a Textbox field is changed. I am using an OnTextChanged event handler in the Textbox field and the event fires ok upon the Textbox field being changed. However it only works when I click on another field after changing the textbox. Is there any way to make the event fire upon changing the textbox even before leaving the Textbox field? I did not see any OnKeyPress event property in the Textbox class. I think I saw some Javascript examples. However I am not yet familiar with Ja...

how to get an html check box checked value in code behind.
iam having a grid where i palced a check box in the grid header .now how can i get the checked state of the control in a button clicked Hi, CheckBox chk =GridControl1.Control.FindControl("ChkId"); Where chkId is the id of the checkbox that you have in the grid control. Then check that if(chk.Checked) {"Do something here"}. Regards Ramesh   Dim chk As CheckBox = GridView1.HeaderRow.FindControl("CheckBox1") If chk.Checked Then ''.... End If Regards,Anas Ghanem.Note:Please Don't hesitate to click...

check to see if check box is checked onclientclick button event.
i have a check box similiar to "please check the box if you have read and understand what i placed there".  Right now i have the submit button doing a postback and checking to see if the checkbox is checked. great but inefficient.  I would like to use the onclientclick to check if the checkbox is checked and if not alert the user to check the box.  Thank you in advance and your help is appreciated.  I am very new to this javascript stuff so please spare me.  I am keeping the code inside my aspx file, not in codebehind. Jake You should look at using a validatio...

Web resources about - Check Box changes other check boxes - asp.net.getting-started

Next Republican Debate Schedule: When Does Donald Trump Face Ted Cruz, Megyn Kelly, Other Candidates ...
When is the next Republican presidential debate? The schedule was announced last month by Fox News, the network that hosted the first debate ...

Google Paid Apple $1 Billion In 2014 For Privilege Of Search Bar On iPhone
When you go to perform a Web search on an iPhone, the phone automatically chooses Google for you. Why? There are other fine search engines out ...

Facebook Is Bringing 3D Touch To Your Timeline
Facebook is bringing 3D Touch to its Timeline, the company says – meaning that users of Apple’s latest devices, the iPhone 6s and iPhone 6s Plus ...

Everything you need to know to track this weekend’s winter storm
If you're in the Northeastern United States, you're likely aware that the first massive snow storm of the winter season is currently bearing ...

Florida Police Officer Wounded in 'Ambush' Shooting
A south Florida police officer has been shot and wounded in what his chief is calling an ambush attack

EPA regional head steps down after agency rules response to Flint water crisis “inadequate”
As the water crisis stemming from lead contamination continues in Flint, Michigan, the head of the Midwest region of the U.S. Environmental Protection ...

US stocks join global rally as energy prices jump again
U.S. stocks are jumping Friday as a rally that started in Asia reaches America and energy prices continue to climb from their recent lows, lifting ...

Reese Witherspoon and John Krasinski Criticize the Oscars' Lack of Diversity
Reese Witherspoon and Jim from The Office have added to the growing criticism about the Oscars’ lack of diversity. Read more...

Another Clue Apple Is Experimenting With Virtual Reality
Apple has added another notable name in the virtual reality industry to its team. The Cupertino, Calif.-based company recently hired VR expert ...

Somali Security Forces End Siege At Beachfront Restaurant; At Least 20 Dead
Huffington Post Somali Security Forces End Siege At Beachfront Restaurant; At Least 20 Dead Huffington Post Witnesses said that gunmen shouted ...

Resources last updated: 1/22/2016 5:25:50 PM