Link to home
Start Free TrialLog in
Avatar of pamela rizk
pamela rizkFlag for Lebanon

asked on

create click event on imane button in asp

dear all

i created an image buton programatically in asp net
below is the code:
  Dim m_htmltable As New HtmlTable
        Dim m_htmlRow As New HtmlTableRow
        Dim m_htmlcell As New HtmlTableCell
        m_htmltable.Rows.Add(m_htmlRow)
        m_htmlRow.Cells.Add(m_htmlcell)
        m_htmlcell.Attributes.Add("width", "auto")
        m_htmlcell.Attributes.Add("height", "22px")
        m_htmlcell.Attributes.Add("white-space", "nowrap")
        m_htmlcell.Attributes.Add("class", "textBoxStyle_NoBorder")
        m_htmlcell.Attributes.Add("text-align", "center")
        m_htmlcell.BgColor = "#ECF5FF"

        Dim createDiv As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV") 'create div element with the below styles:Style = "display: inline-block ; white-space: nowrap;"
        createDiv.ID = "createDiv"
        createDiv.Style("display") = "inline-block"
        createDiv.Style("white-space") = "nowrap"
        Dim img As New ImageButton()
        img.ImageUrl = "../../Images/NewIcons/deleteline_Dis_Icon.png"
        img.CommandName = "image_clicked"
        img.CommandArgument = m_htmlcell & ";" & FileNat & ";" & FileNumber & ";" & FileName
        img.Width = "15"
        img.Height = "15"
        img.Attributes("display") = "inline"
        img.Attributes("vertical-align") = "middle"
        img.Attributes("cursor") = "pointer"
        img.Attributes("vertical-align") = "middle"
        AddHandler img.Command, AddressOf img_Click
        Dim CellNbre As String = m_htmlRow.Cells.Count
        Dim File_Link As New HyperLink
        File_Link.Target = "_blank"
        File_Link.ForeColor = System.Drawing.Color.Black
        File_Link.Text = FileName.Replace(" ", "")
        File_Link.NavigateUrl = FileLink

        m_htmlcell.Controls.Add(img) '// append DIV to the table cell
        m_htmlcell.Controls.Add(File_Link)
        createDiv.Controls.Add(m_htmltable)
 Protected Sub img_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
       m_htmlcell.Style("display") = "none"

Open in new window


i need on image click to hide the the cell where the image is created
how to do that ?
Avatar of pamela rizk
pamela rizk
Flag of Lebanon image

ASKER

i need onc ei click on delete image to close the division where the image is ?
I BRIEF I AM CREATING AN IMAGE BUTTON INSIDE A TABLE AND THIS TABLE INSIDE A CELL
I NEED TO ADD AN EVENT ON CLICK FOR TEH IMAGE AND TO HIDE THE DIVISION WHERE THE IMAGE IS PLACED.HOW TO DO THAT?
This would be easier to answer if you had posted the HTML that is rendered from your VB code.  But in any event, I think I understand what the HTML should look like.  You've created a table with an image button that's inside a div.  You want to hide the div if the button is clicked.

Here is a Fiddle Demo showing how to hide a div on a button click.

HTML
<div id=createDiv>
  <table>
    <thead>
      <tr>
        <th>Col 1</th>
        <th>Col 2</th>
        <th>Col 3</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>1a</td>
        <td>1b</td>
        <td>
          <input type="button" class="btn" value="Click Me">
        </td>
      </tr>
      <tr>
        <td>2a</td>
        <td>2b</td>
        <td>
          <input type="button" class="btn" value="Click Me">
        </td>
      </tr>
      <tr>
        <td>3a</td>
        <td>3b</td>
        <td>
          <input type="button" class="btn" value="Click Me">
        </td>
      </tr>
    </tbody>
  </table>
</div>
<input id="btnToggle" type="button" value="Toggle Table Visibility">

Open in new window


jQuery
$('.btn').click(function() {
  $('#createDiv').hide();
});

$('#btnToggle').click(function() {
  $('#createDiv').toggle();
});

Open in new window

yes but this table is created programatically
how to do that
any news?
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
k
I re-read my last comment and want to add:  You could do an autopostback on click, which would return control to the server side code, where you could set the control's visibility to false.  However, unless you have a particular reason why you can't use jQuery, jQuery is better suited for this scenario.  It's faster and more efficient.