Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-10
6
Medium Priority
?
572 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 900 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 900 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

705 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