Solved

create click event on imane button in asp

Posted on 2016-08-17
8
64 Views
Last Modified: 2016-09-02
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 ?
0
Comment
Question by:pamela rizk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:pamela rizk
ID: 41759456
i need onc ei click on delete image to close the division where the image is ?
0
 

Author Comment

by:pamela rizk
ID: 41759481
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?
0
 
LVL 43

Expert Comment

by:zephyr_hex (Megan)
ID: 41759559
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

0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:pamela rizk
ID: 41760543
yes but this table is created programatically
how to do that
0
 

Author Comment

by:pamela rizk
ID: 41760593
any news?
0
 
LVL 43

Accepted Solution

by:
zephyr_hex (Megan) earned 500 total points
ID: 41761130
It doesn't matter if the table is created "programatically".  When the web browser renders the page, it's HTML.  The client only sees and interacts with HTML.

In other words, the server side code is translated into HTML, and that's what the user sees and interacts with.

If you want an event to be triggered when a client clicks on a button, that must be done in JavaScript / jQuery.  JavaScript / jQuery operate on HTML.  Not server side code.

So, the jQuery I gave above should give you a baseline to work with.  I provided HTML so you (and others) have a working demo.  I've guessed at what your HTML might look like -- and really, anyone who answers this question will need to know or guess at what your HTML looks like -- because that is what jQuery / JavaScript operate on.

Run your server side code and look at the HTML that's rendered.  The structure of that HTML is what is necessary for jQuery / JavaScript to work.
0
 

Author Closing Comment

by:pamela rizk
ID: 41781164
k
0
 
LVL 43

Expert Comment

by:zephyr_hex (Megan)
ID: 41781710
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.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

724 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