0

I'm creating a wizard using an ASP.NET MultiView control. On each of the views, I have a HTML table row containing the navigation buttons for the wizard ("Previous", "Next",...).

<tr class="rowNavButtons">.. Nav buttons go here ..</tr>

On the summary view of my wizard, I have an "Edit" button that will navigate to a specific view. I would like to hide the < tr > (containing the nav buttons) when in Edit mode.

The issue is that I have multiple instances of that Nav row in my MultiView, and I cannot assign an ID for each one of them. They do share a CSS class.

Is there a way to access all of the HTML elements that share the same CSS class? Is there another way to group HTML elements?

I've already took a look at the solutions described here: I cannot use JavaScript or jQuery, and the C# solution is generating a "System.StackOverflowException" lol Also, that thread is 4 yrs old so I was hoping there might be a newer solution :)

Thanks!

Community
  • 1
  • 1
mustang888
  • 205
  • 1
  • 2
  • 16
  • actually this would be very easy to accomplish if you just assigned an id for each of them, but may I ask why you don't want to use javascript? – jack Apr 08 '14 at 16:28
  • Yes, the newer solution you were referring is to use jQuery :) – Arman Apr 08 '14 at 16:47
  • 1
    You will have only 1 View active (visible) at a time right? So you don't really need to hid *all* of them when you click Edit, just one - in current view? – Yuriy Galanter Apr 08 '14 at 16:53
  • @BlackBaron yeah assigning an ID for each of them is an option, but I did not want to list everything single row in my code behind and toggle the visibility.. I'd rather just loop through (simply because, if I add more Views - and hence more rows - and will have to revisit my code-behind and those) – mustang888 Apr 08 '14 at 17:45
  • 1
    @BlackBaron@Arman lol yes I guess jQuery is the newer solution. The reason I'd rather not go with a client-side solution is that it will not remove it from the DOM and the "hiding" will happen after it is rendered in HTML.. Also, the application will be used by the client who uses IE8 (or maybe older?) and I'm worried about unpredictable behavior of the browser.. they should obviously upgrade their browsers but that's a whole other problem :) – mustang888 Apr 08 '14 at 17:50
  • @YuriyGalanter that is correct. I can also hide the row for the active view.. but how to find the row from code behind without assigning an ID to it? And if I assign an ID to it, does that mean I will have to implement some sort of switch/case based on the active view? – mustang888 Apr 08 '14 at 17:52

1 Answers1

0

Give that row attribute runat="server"

<tr runat="server" class="rowNavButtons">.. Nav buttons go here ..</tr>

then you can access it server side. For example, assuming this is one and only such row within a View, and you need to locate it in the active View of the MultiView - you can do something like this:

HtmlTableRow tr = MultiView1.GetActiveView().Controls.OfType<HtmlTableRow>.Single();
tr.Visible = false;

But frankly - it's a hack. Do this on client side. If you cannot use jQuery - do it in plain JS, it's not much more complicated.

Yuriy Galanter
  • 38,833
  • 15
  • 69
  • 136