Solved

Getiing info from HTML components

Posted on 2004-08-24
6
164 Views
Last Modified: 2010-04-15
Hi All,

I have a ASPX page with a <div> and a <panel>.

In my code I gegerate a table on the fly and place it inside the panel.

The table has check boxes in it and there is javascript to handle the turning of checkboxes on and off ...

I now want to know if when I press an <asp:button> how do I get the state of which of the check boxes were pressed.

I also need to know, if I decide im y C# code to change the boxes that were checked, how do I send that info back to the page ...

Txs
Peter
0
Comment
Question by:Pete2003
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
nhewitt21 earned 500 total points
ID: 11882988
code that goes in datagrid to make checkbox:
<ItemTemplate>
      <asp:Label id="DeleteCheckBox" text='<%#"<input class=\"search\" type=\"checkbox\" name=\"DeleteCB" + (DataBinder.Eval(Container.DataItem,"ID").ToString()) + "\" value=\"" + (DataBinder.Eval(Container.DataItem,"ID").ToString()) + "\"/>"%>' runat="server" /></ItemTemplate>

i have an input button:
<input id="DelSelected" name="DelSelected" runat="server">

in my codebehind:
private void DelSelected_ServerClick(object sender, System.Web.UI.ImageClickEventArgs e)
{
      foreach (string var in Request.Form)
      {
            if (var.IndexOf("DeleteCB") > -1)
            {
                  //calls function that removes item from database (via id)                  
                  DeleteFromPhotoAlbum(Convert.ToInt32(Request.Form[var].ToString()));

thats how i did it, there a bit more code
            }
      }
}

That works ok.
hope it helps you out.
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11883028
private void DelSelected_ServerClick(object sender, System.Web.UI.ImageClickEventArgs e)
{
     foreach (string var in Request.Form)
     {
          if (var.IndexOf("DeleteCB") > -1)
          {
               //calls function that removes item from database (via id)              
               DeleteFromPhotoAlbum(Convert.ToInt32(Request.Form[var].ToString()));
          }
     }
}
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11883081
and this:
this.DelSelected.ServerClick += new System.Web.UI.ImageClickEventHandler(this.DelSelected_ServerClick);

needs to go inside the InitializeComponent() for the OnInit
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Pete2003
ID: 11889919
Hi,

Thanks for the info I'm however lost right at the beginning .. what is the <itemTemplate> stuff ??

The way I did my table is just simple generation within a <panel> ...

0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11890113
ahh, i have misunderstood what you was trying to do.  I had assumed you was using a datagrid.  My bad, sorry.

The item template just creates a template column in the datagrid and puts checkboxexs in each row.  If your using a table then forget the template bit and the rest of the code should be enough for you to do what you need to do.
0
 

Author Comment

by:Pete2003
ID: 11892768
Ok I am really trying hard to understand how you are working this, but to no avail ...

There is no relevant data in the Request.Form as the table is in a panel which does not even appear in the form ...

Here is my ASPX page:

<DIV style="WIDTH: 791px; POSITION: relative; HEIGHT: 140px" ms_positioning="GridLayout"
      id="div1" runat="server">&nbsp;
      <asp:panel id="tablePanel" style="Z-INDEX: 102; LEFT: 0px; OVERFLOW: auto; POSITION: relative"
            Height="200px" Width="100%" Runat="server"></asp:panel>
</DIV>

I now use my codebehind to populate the tablePanel with a LiteralControl containing the HTML Table:
ie:

string sHTML = "<table><tr><td>Hello</td><td>Hello</td></tr></table>";
tablePanel.Controls.Add(new LiteralControl(sHTML));

Now I need to be able to access the "Hello" and "World" from my C# code ...

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SqlDependency to get update from sql to my c# app 2 63
VB: Convert 2 dates to specific format 24 52
.NET 2008 VB and C# 6 39
c# - Best approach for objects in functions 3 24
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question