Question

I'm still getting my head around asp.net.

I followed some online examples of using multiviews and got them working just fine when I use something like a Menu class as the trigger to select the active view. Having the onClick event makes it pretty easy.

But I can't figure out how to change the emmited code from the Menu control.

I have the following multiview control...

<asp:View ID="0" runat="server">

   <p>view page 1</p>

</asp:View>

<asp:View ID="1" runat="server">

   <p>view page 2</p>

</asp:View>

And I need to have the following structure used to trigger the views. (Note: this needs to be what gets emitted to the browser. Not necessarily the literal code in the aspx page)

<a class="button large-plain" href="" >
    <span>
        See page 1
    </span>
</a>
<a class="button large-plain" href="" >
    <span>
        See page 2
    </span>
</a>

For clarification: we have a style sheet provided by an exteranl designer that works with the above markup. If I could just make the triggers asp button controls, or a menu control, it would be easy. But the style sheet doesn't work then, and I'm told the world will end if the style sheet doesn't work.

Can I customise a Menu control so that it outputs this kind of structure? (And if so, how?)

I could just hard code the links that trigger the views (the structure is not going to change). But if I hardcode it, how do I call the onClick event what the links are clicked?

Was it helpful?

Solution

I think you might be able to try the following to change the tags into server-side controls and then use that as the trigger. Adding ID and runat="server" to any html element means that you can then access them programmatically as you would any other .NET style control. Additionally if you're using .NET 4.0 you can also add the ClientIdMode="Static" attribute so that the ID's are as you typed and not modified by ASP.NET.

To solve the Click problem you can add the OnServerClick="" attribute to specify which method to call on the server when the link is clicked.

<a class="button large-plain" href="" ID="ViewPage1" runat="server" OnServerClick="ViewPage1_Click">
    <span>
        See page 1
    </span>
</a>
<a class="button large-plain" href=""  ID="ViewPage2" runat="server" OnServerClick="ViewPage2_Click">
    <span>
        See page 2
    </span>
</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top