Label Click in Repeater with Datacolumn

Starr Duskk
Starr Duskk used Ask the Experts™
on
I have a label in a repeater. The label has an onclick event, which requires it use an apostrophe rather than a double quote. But I also use a datacolumn in the onclick event as a parameter and it requires a single quote.

I've tried escaping the single quote inside the onclick event. No.
I've tried leaving out the quote when I pass the parameter. No.

Here is what I have:

<asp:Label ID="btnViewMore"
Text='<%# Eval("dcViewMore").ToString()%>' CssClass="stylViewMoreBtn"
OnClick='loadOverview("<%# Eval("dcEmployeeId").ToString()%>;return false;")' runat="server"></asp:Label>

Open in new window


How do folks use a datacolumn in an onclick event where a single quote is required? thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Starr DuskkASP.NET VB.NET Developer

Author

Commented:
If I use two apostrophes:
The server tag is not well formed.
If I use a double quote with an apostrophe.
The server tag is not well formed.

If I use this:

OnClick='loadOverview("<%# Eval("dcEmployeeId").ToString()%>")'

Open in new window


viewing source looks like this:

OnClick="loadOverview(&quot;&lt;%# Eval(&quot;dcEmployeeId&quot;).ToString()%>&quot;)"

Open in new window

Starr DuskkASP.NET VB.NET Developer

Author

Commented:
I figured out:

in front:

                                <asp:Label ID="btnViewMore"
                                    Text='<%# Eval("dcViewMore").ToString()%>' CssClass="stylViewMoreBtn"
                                     runat="server"></asp:Label>
                                  <asp:HiddenField ID="hdnEmployeeId" Value='<%# Eval("dcEmployeeId").ToString()%>' runat="server" />

Open in new window


behind:

I have an ItemDataBound...

    Private Sub repRepeater_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles repRepeater.ItemDataBound

(...snip)...

             Dim hdnEmployeeId As New HiddenField
                hdnEmployeeId = CType(e.Item.FindControl("hdnEmployeeId"), HiddenField)

                Dim btnViewMore As New Label
                btnViewMore = CType(e.Item.FindControl("btnViewMore"), Label)
                Dim cmdArgument As String = hdnEmployeeId.Value

                btnViewMore.Attributes.Add("onClick", String.Format("loadOverview('{0}')", cmdArgument))

    End Sub

Open in new window

ASP.NET VB.NET Developer
Commented:
see above.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial