Solved

adding a javascript function call to button in repeater to hide a row

Posted on 2011-03-10
6
566 Views
Last Modified: 2012-05-11
Hi,

I have a repeater.

On the rptResults_ItemDataBound

I find a button and a html table row.
Dim trInvoices As HtmlTableRow = Nothing
        Dim btnShow As Button = Nothing

btnShow = CType(e.Item.FindControl("btnShow"), Button)
            trInvoices = CType(e.Item.FindControl("trInvoices"), HtmlTableRow)

I then have:
btnShow.Attributes.Add("onclick", "javascript:showdiv(" & trInvoices.ClientID & ")")

Firstly when I am clicking the button at the mo it is just posting back to itself.

Secondly should that code then work to hide the html table row which is coded as :
<tr id="trInvoices" runat="server" visible="false">

Thanks in advance
0
Comment
Question by:scm0sml
[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
6 Comments
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 225 total points
ID: 35096943
You have forgotten the apostrophes around the string that contains the id, and you would have to return false from the onclick event to keep the button from posting the form:

  btnShow.Attributes.Add("onclick", "javascript:showdiv('" & trInvoices.ClientID & "');return false;")
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 225 total points
ID: 35096967
Your main problem will be that you have set your row to visible='false', this means that the control will not be rendered at all.
Change it to :
<tr id="trInvoices" runat="server" style="display:none">
0
 
LVL 6

Assisted Solution

by:Webmonkey
Webmonkey earned 50 total points
ID: 35096969
We'd need to see how you have showdiv written first.

Otherwise keep in mind that, on the server-side, the Button is an ASP.Net control, not an HTML button.  So javascript calls that you enter in the onclick event will be evaluated and run on the server-side.  Alternatively, you can use the onClientClick attribute to have it fire a javascript on the client side.  

That would look something like:

btnShow.Attributes.Add("onClientClick", "showdiv(" & trInvoices.ClientID & ")")

Open in new window


[Note that in the client-side onClick event, specifying "javascript:" is not necessary.]
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35097005
In your showDiv function to make the row visible you would then use:

myRow.style.display = 'block';
0
 

Author Closing Comment

by:scm0sml
ID: 35097008
Excellent thanks guys.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 35097133
@Webmonkey: That is not correct. OnClientClick is a control property, not an HTML attribute. If you add it as an attribute you should use "onclick".
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

634 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