Storing the checked Htmlimputcheckbox values on client side and passing to server side on submit button clicked

Hi All

 I've got these bunch of HtmlInputcheckboxes that i'm creating dynamically using div.innerhtml on server side and putting it in a <TD> block, calculate averages etc. Things are working fine until this point. Now i need to get all the checked checkboxes and their values(which are dates in my case) and pass these values back to server side for processing on the submit button click. But i'm using a pagefooter submit button to fire my submit button so i cannot directly pass these values to my submit button onclick method. I tried to use the findcontrol method on my code behind as i set my htmlinputcheckbox runat=server but i couldn't access the checkboxes on my code behind(VB) i was trying to see if i can find a way to do it on client side and pass the dates array back to server. Any suggestions are welcome. Also any of you had a situation where you'd to use both javascript coding and serverside coding for any server controls? or do lots of javascritping and access their checked property in codebehind? Pls let me know how you did it as far i see i can do it using registerscriptblock etc but my javascript function would be too long to embed in the string variable. Pls advise

 

I tried using the asp server checkboxes but for some reason they're not showing up in my dynamically created table. Thanks a lot

 

0
DotNet123
9/19/2007 8:28:24 PM
asp.net.client-side 24353 articles. 1 followers. Follow

3 Replies
882 Views

Similar Articles

[PageSpeed] 49

The easiest way is to add the runat="Server" property to each control and the control will then be able to be accessed server-side.

NC...

0
NC01
9/20/2007 12:18:18 PM

But even after i've done that i'm unable to access them on the server side prob because i've written out innerHtml for building the page and the controls. Pls advise.

 

Thanks

0
DotNet123
9/20/2007 1:00:20 PM

This should work for you, using ASP.NET dynamic CheckBoxes.

/////////////////////////
// aspx file
/////////////////////////

<form id="Form1" method="post" runat="server">
 <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder>
</form>

/////////////////////////
// aspx.cs file
/////////////////////////

protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;

private int _numberOfCheckboxes = 10;

protected override void OnInit(EventArgs e)
{
 //
 // CODEGEN: This call is required by the ASP.NET Web Form Designer.
 //
 InitializeComponent();
 base.OnInit(e);

 this.CreateCheckBoxes();
}  

protected virtual void CreateCheckBoxes()
{
 // Clear out the PlaceHolder...
 PlaceHolder1.Controls.Clear();

 // Create a new Table...
 HtmlTable htmlTable = new HtmlTable();
 htmlTable.Width = "300px";
 htmlTable.Border = 0;
 htmlTable.CellSpacing = 1;

 for (int i=0; i<_numberOfCheckboxes; i++)
 {
  // Create a new TableRow...
  HtmlTableRow htmlTableRow = new HtmlTableRow();

  // Create a new TableCell...
  HtmlTableCell htmlTableCell = new HtmlTableCell();
  
  // Create a new CheckBox...
  CheckBox checkBox = new CheckBox();

  // Create a unique ID for the CheckBox...
  checkBox.ID = "CheckBox_" + i.ToString();

  // Add the text to the CheckBox...
  checkBox.Text = "#" + i.ToString();

  // Add the CheckBox to the TableCell...
  htmlTableCell.Controls.Add(checkBox);

  // Add some other properties to the TableCell...
  htmlTableCell.ColSpan = 4;
  htmlTableCell.Width = "300px";
  htmlTableCell.NoWrap = true;

  // Add the TableCell to the TableRow...
  htmlTableRow.Cells.Add(htmlTableCell);

  // Add the TableRow to the Table...
  htmlTable.Rows.Add(htmlTableRow);
 }

 // Add the Table to the PlaceHolder...
 PlaceHolder1.Controls.Add(htmlTable);      
}

private void Page_Load(object sender, System.EventArgs e)
{
 if ( this.IsPostBack )
 {
  // Read the current values of the CheckBoxes...

  for (int i=0; i<_numberOfCheckboxes; i++)
  {
   string checkBoxId = "CheckBox_" + i.ToString();
   Control controlRef = this.FindControl(checkBoxId);

   if ( controlRef != null )
   {
    CheckBox checkBox = (CheckBox)controlRef;
    Response.Write("#" + i.ToString() + " Checked = " + checkBox.Checked + "<br>");
   }
  }
 }
}

NC...

0
NC01
9/20/2007 1:22:40 PM
Reply:

Similar Artilces:

Firing both Client side event and server side event for server side button
I am having some difficulties getting this to work.. I have button_click (Asp.net) and ClientClick (Javascript).  Javascript is firing fine.  Server script is not. may be you have return return false in the in the javascript which is why its not firing server side event.You should add javascript evelt like thisbutton1.onclientclick = "functionname" Function should nopt return false. Vikram www.vikramlakhotia.comPlease mark the answer if it helped you...

How to pass the client side values to server side?
 hello to All,Actually i wanna implement a code like... a string in HTML textbox retrieve in server side control....suppose i hv a HTML control <input type="text" id="txtHTML"/>, and dis control  txtHTML.text="abc".now i want to retrieve dis client side string "abc" in d server side textbox named "txtASP"...which hs a property runat="server"so please give me an idea how to pass values from client side to server side.... hope u understand a problem... sam.  You could do this <input type="text"...

How to pass values from client side to server side
Hi, Is there a way to transfer variable from a client loop to a server loop. For example: var clitest = 'test'; Now I would like to get test variable from javascript into a server string variable <% sertest = ?? %> I understand that this can be done by storing a variable into a hidden control for example and than access it using server side, but when I have to transfer an array for example it get's a little more complicated. I was wondering is there more efficient approach? You can't transfer arrays, only strings. To workaround this problem pass delimited stri...

Check values in client side then go to server side
Hi, I am developing an application that allows users to update their personal informations. I want to check if mandotary fields are empty or not in client side with a java script when the user press the update button. If all mandotary fields are full(that will be decided with a java script), then server side function which updates the related database table will be run. How can I do this... I don't want to check mandotary fields in server side. I am sure, there should be an easy way. How ... ? Thanks. Sure... use a custom validator and name your javascript function to run. Inside...

how to pass values from client side to server side #2
Hi Guys....               This is Aani....I'm using ASP.NET in C# language.i have created one webpage for get input from user(from java script inputbox).i want that entered data in server side operations.how can i pass that value from client side server side.i need proper code in C# language.reply me soon... Thanks is Advanced... Regards....Aani plz use hidden field.ur assing values to text boxes through java script. before post back call a java scipt function to assign value to hodden fieed. even u can add these ...

Problem passing value client-side to server-side
I have a page that calls a pop-up while passing an encrypted value via a query string. The value is encrypted on the parent client-side in javascript so it needs to be decrypted client-side as well. This decryption occurs on closing the child (popup) and I am at a loss of when and how I should get this value to the server-side. On the popup you just want to process server side code? Anytime you can access for example the raw url:string raw = Page.Request.RawUrl;If you need to access any values on the client side you can access the url using javascript. Another idea is to, on the code beh...

passing client side variable value to server side
 i have a grid and  by click on the rows, the onrowclick event is fired on client side. I want to pass the row index to the server side. As there are not sessions variables in javascript so i am stuck to pass the row to the server side.. I have made a texbox and set its valueto the index in the onrowclick event but when refresh calls, the text box became empty as the value set is on client side, i want page to persistthe value,  How can i do that? Tel me some way passing the row index to the server side?? Hi, You can call GridView_SelectedIndexChanging event on row click ev...

Calling server side sub from client side button click
Hi, I have some javascript in my asp.net page, and a function within that, which is run when the client side form is submitted. What I need is for that function to run, which updates a server side variable, then following that a server side sub should run, using that (newly updated) variable. I have currently set it up with the  onsubmit= tag of the client side form running the first (JavaScript) function, and then the submit button at the bottom of the client side form calling the server side sub with its onClick property. The (probably quite daft!) thinking behind that was that the on...

Client side code to pass values to server side variable?
Hi there, I have ListBox_SelectedTextChanged() method that creates another list box in the runtime as follows: // Get Action Level List lbxActionLevel = new ListBox();lbxActionLevel.ID = "ddlA" + i.ToString(); lbxActionLevel.Width = 100; lbxActionLevel.Rows = 2;SqlDataReader dr = new BusinessLogicLayer().bllGetActionLevels(); lbxActionLevel.Items.Clear();while (dr.Read()) {ListItem lAction = new ListItem(); lAction.Text = dr.GetString(1).Trim();lAction.Value = Convert.ToString(dr.GetInt32(0)); lbxActionLevel.Items.Add(lAction); lbxActionLevel.SelectedIndex = 0; } I ...

How to pass param values from server side to client side scripts
Hi, I have a page containing a datagrid with a list of geographic positions of interesting places. Users can filter this grid. Clicking an item the system displays the place on a map using MS Virtual Earth map component that exposes a client side javascript api. My problem is that the filtering is done on server side, but the map runs on client side. So during page load, I need to create long strings containing complex javascript codes on the server side, and add it as an event handler attribute to my components. This causes a lot of problems, for exemple...

Passing a value from server side to client side without postback
My problem exactly is that on my aspx.vb code-behind, I can update the field using HiddenField ID = "hidSessionTimeout" Code-Behind: on Page_LoadhidSessionTimeout.Value = HttpContext.Current.Session.Timeout on ChangeTimeOutValue()hidSessionTimeout.Value = 5  Client-Side: var x= document.getElementById("hidSessionTimeout"); It seems that the javascript cannot get the latest updated value... Any ideas?    Any Workaround solution? did u keep the page load code in if(!IsPostBack)pavankumar geljian_a:  Client-Side:  var...

Client-side values to server-side ?
Hi! My previous query is attached below: I have implemented the below mentioned implementation . 'listbox1' on 'webform1' shows all the values from 'webform2'. I have implemented it using javascript. I would like to know that to implement validation on 'webform1', I would require the values of 'listbox1' ,which are on the client-side , to move to the server-side . I think sending a querystring will be fine but how to implement it using javascript and code-behind(C#)? Your suggestion will be appreciated. Thanks and regards, ap.       My previous query: " I am stuck wi...

Client Side values to Server Side
What is the best way to transfer Client Side values to the Server side? For example I have a variable "var1" in javascript. var1 = "sample"; How can I acquire this value in the server side?  What is the best approach for this?  Barry to send the value to the server during a postback, you need to place the value in an input control.  You could consider using a hidden textbox for that purpose.Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ In the JavaScrip...

How to access Client Side control in server side button click event?
Hi all, I need to access client side control from server side code. For an example <form id="form1" runat="server"> <table> <tr> <td>UserName:</td> <td><input type="text" id="textBoxUserName" /></td> <td><asp:Button ID="buttonShow" runat="server" Text="show" OnClick="buttonShow_Click" /></td> </tr> </table>   </form> I need to access the textBoxUsername in the server side button click event. How to do that? Than...

Web resources about - Storing the checked Htmlimputcheckbox values on client side and passing to server side on submit button clicked - asp.net.client-side

Resources last updated: 12/25/2015 1:58:04 PM