Solved

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

Posted on 2011-03-10
6
535 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

16 Experts available now in Live!

Get 1:1 Help Now