I have this code:
<strong><a <%# Eval("DsPathDocumento") != null && !String.IsNullOrEmpty(Eval("DsPathDocumento").ToString()) ? String.Concat("href='/UpLoads/", Eval("DsPathDocumento"), "'") : "style='cursor: default; color:#000000;'" %>>
<%# Eval("NmTipoDocumento")%>
</a></strong>
I happen to need to apply a javascript through this class: class="linkUpload"
This class can only happen when I create the hyperlink, otherwise the class can not be called. Any attempt by me to put this class did not work. If I put it right after a, type: <strong><a class="linkUpload" <%# Eval("DsPathDocumento") != null && ...</a></strong>
, when I have document it calls the popup, ok, correct and when I do not have link, also calls the popup blank. It always mounts the href, even without attached document, as I discussed here in SOPT. Below my javascript:
$(document).ready(function () {
$('.linkUpload').click(function (event) {
event.preventDefault();
window.open($(this).attr("href"), "popupWindow", "scrollbars=yes");
});
});
The question is: How do I assign javascript to the class only when there is attached document.
So: If I have attached document, the ternary expression above in the post, should perform the step after the symbol "?" and if it does not have an attachment, then it performs the step after the ":", right? Well, it turns out that anyway and I do not know why, it's creating the underline regarding href even when there is no attachment. I have the class "linkUpload" that should only be executed when there is attachment. If I put this class right after the "a" tag, it stays true for all situations in the ternary expression, that is, with or without an attachment and I can not call an expression or html command from within the Asp.Net tags, then generated the post: How do I assign the function only when there is a link, ie only when the first part of the ternary expression is executed.
What I want is this, or something similar. I have this asp.net tag: <% %>
. How would I call this class: class="linkUpload"
within the asp.net tag?
I tried to do an if to take better, I think, and I can not. I tried in many ways and this way was the last attempt before this post.
<%if(Eval("DsPathDocumento") != null && !String.IsNullOrEmpty(Eval("DsPathDocumento").ToString()))
{ %>
<strong><a class="linkUpload"
<% String.Concat("href='/UpLoads/", Eval("DsPathDocumento"), "'") %>>
</a></strong> <%}%>
<%else
{ %>
"style='cursor: default; color:#000000;'"
Eval("NmTipoDocumento")
<%}%>
I changed to this form and gave the following error:
<% if(Eval("DsPathDocumento") != null && !String.IsNullOrEmpty(Eval("DsPathDocumento").ToString()))
{%>
<strong><a class="linkUpload"
<% String.Concat("href='/UpLoads/", Eval("DsPathDocumento"), "'"); %>>
</a></strong> <%}%>
<%else
{ %>
<"style='cursor: default; color:#000000;'">
Eval("NmTipoDocumento")
<%}%>
This is the error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.