Solved

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

Posted on 2011-03-10
6
545 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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