Solved

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

Posted on 2011-03-10
6
524 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
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now