0

I have a particular link that I'm trying to convert to an ASP:LinkButton place holder so that I can control it's visibility based on the user type:

<asp:LinkButton id="linkColumnsSelect" runat="server" Text="Select CSV Columns for Export" Href="javascript: void(0)" Visible="True" />

I was able to remove the PostBackUrl by adding "javascript: void(0)" to the Href property, but now I have the problem of getting a real ID that I can use in javascript. As it currently stands, this creates an ID for the item of ctl00_ContentPlaceHolder1_linkColumnsSelect, however I need that ID to be "linkColumnsSelect" on the client side and still work server side (for jQuery coding reasons that involve looping). Is that possible? Or do I just need to adjust my jQuery to account for the placeholder segments of IDs?

Dexter
  • 795
  • 2
  • 13
  • 27
  • It's looking like I'm going to have to just account for the longer IDs in my jQuery. I just don't know much about how these IDs are generated, so I'm unsure how predictable they are once I start adding more code. – Dexter Apr 08 '11 at 21:08

1 Answers1

0

You can do this with jquery:

$("*[id$='TextBox1']").show();
Oskar Kjellin
  • 21,280
  • 10
  • 54
  • 93
  • I need for it to be completely hidden from the client, **including in the source code**, for security reasons. This is why I was switching to the control instead. – Dexter Apr 08 '11 at 21:06
  • @Dexter I don't understand what you want to do. Wasn't the problem that you couldn't reference the item because the id was generated from the server code? My answer solves that. Btw you should not hide it with javascript if it needs to be hidden because you can just disable JS and then you'll see it – Oskar Kjellin Apr 08 '11 at 21:50
  • Sorry, I guess I should have been more clear as to my intentions. I am, in fact, trying to make this link dynamic rather than static, so that I can show or not show it from the server code based on the user type. The reason I'm having a hard time with the Javascript is that I have several controls that hide and show certain modal dialogs, and the script that is adding the click events loops through a table of corresponding HTML strings and such, using a naming convention that allows me to treat the IDs as part of a virtual array. The naming convention the VB.net uses is making it difficult. – Dexter Apr 11 '11 at 14:40
  • I guess the question I should be asking is how can I better control the VB.net ID assignment. – Dexter Apr 11 '11 at 14:41
  • @Dexter still not clear why my code wouldn't work for you. What it does is that it picks out the control where the id ends with whatever (in your case it would be "linkColumnsSelect") as the VB.net client ids always end with their server ids. But don't do this using javascript, instead just show or hide using service side code. Don't even generate it if you shouldn't show it. – Oskar Kjellin Apr 11 '11 at 19:43