I have list li,I want to know which option in clicked to code behind.How can i possible
<ul class="mega-select__sort">
<li class="filter-wrap"><a href="#" id="loc" class="mega-select__filter filter--active" runat="server" data-filter='location'>Location</a></li>
<li class="filter-wrap"><a href="#" id="cine" class="mega-select__filter" runat="server" data-filter='cinema'>Cinema</a></li>
</ul>
there are two options one is location and another one is cinema.I want to know which option was clicked to code behind..
You cannot do this. After a page has finished processing and has been sent to a browser as the HTTP response, server can do nothing with this page.
You need to use POST form to inform the server about your choice. Or you can use JavaScript and AJAX, if you want it to be done without form submitting and reloading.
Use repeater control or Datalist control to list the <li> tag. Inside <li> take linkbutton. then use itemcommand method to handle it
Related
I try to open popup from linkbutton inside repeater. Here is my code:
<asp:Linkbutton cssclass="blue-button" id="LinkbtnPrint" runat="server" CommandName="PrintItem" CausesValidation="false" OnClick="javascript:dnnModal.show('<%# DotNetNuke.Common.Globals.NavigateURL("RptAppendixI","doanhnghiepid",Request.QueryString["doanhnghiepid"],"NamBC",NamBC2.ToString(),"ThangBC",ThangBC2.ToString(),"mid",Moduleid.ToString())+"?popUp=true" %>',false,580,950,false)">
<i class="fa fa-print" aria-hidden="true"></i>
</asp:Linkbutton>
I get the error message: "System.Web.HttpParseException: The server tag is not well formed.".
How can I fix this problem?
Its probably because you're mixing two different technologies, if you're using javascript to handle the request and the way you can avoid the exception is by removing the runat="server" attribute. After that you can handle the command that you're defining in the linkbutton in ajax call to the method from javascript, also there is this. I am not sure what are you trying to do while opening the modal but you can simplify it by creating a function inside the javascript that would handle those values instead of passing them straight away from the click event calling both js framework and dotnet framework at the same time.
OnClick="javascript:dnnModal.show('<%# DotNetNuke.Common.Globals.NavigateURL("RptAppendixI","doanhnghiepid",Request.QueryString["doanhnghiepid"],"NamBC",NamBC2.ToString(),"ThangBC",ThangBC2.ToString(),"mid",Moduleid.ToString())+"?popUp=true" %>',false,580,950,false)
if this doesn't help you could try to remove code above and do ajax call to navigate the url that you're calling on click.
The deal is that when you have the following on your site it works:
Click Me!
But the above fails to work if that site is a nested application.
I have seen two solutions to this opportunity in asp.net.
The first solution that I found was to add the following:
<a runat="server" href="~/Some/Path/file.aspx" class="button">Click Me!</a>
I have not tried this because I feel it would add more crap to your view state.
The solution that I have tried is:
Click Me!
The question is, what is the preferred method of addressing paths in nested applications?
You want to use HyperLink server control. It is meant for that kind of thing.
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl="~/Some/Path/file.aspx"
CssClass="button">Click Me!</asp:HyperLink>
Render as
<a id="HyperLink1" class="button" href="/Some/Path/file.aspx">Click Me1</a>
ASP.Net HyperLink control uses ResolveClientUrl to resolve the given url, so you do not need to do anything.
Is it possible to put a button on my user control .ascx (the web part in this case), and have a customized image with that? What I am trying to do is have a "print" button to print the page.
However, I don't want to use the default asp button, I want to have a the special "print" icon associated with it. So, can I do this and still use <asp:button>?
Or is it just better to make that "print" icon a link, and do OnClick on the link event?
You can use link button as suggested.
But in my opinion you should not use any server-side control if you don't have to use it on server side.
What you can do create an image tag <img src.... and use onclick event on this image.
When you create a server side controls it is added to your view state key value pair of information. Which is an overhead.
or you can use like this
<a href="javascript:window.print()">
<img src="print.gif">
</a>
or even
<img src="print.gif" name="pic" onclick="javascript:window.print()"/>
You could try the ImageButton class, then you can have a printer icon for example.
Try this:
<asp:ImageButton ID="submitButton" runat="server" OnClick="submitButton_Click" ImageUrl="~/images/printer.jpg" />
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?
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>
Adding runat="server" is not rendering my server tags <%...%>
I have a masterpage with a few <li> for menu and since I have to set class=selected for the current page, I am using a little server tag to find the url and assign the particular class.
I have total of 10 <li> and not all menu is available to all types of user, I need to toggle few of the <li> if the user is not admin, so I have runat="server" added to them so I can set their visible=false through c#
Here is how it is at a glance:
<li runat="server" id="liBlog" class='<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>'>Group Blog</li>
<li runat="server" id="liPoll" class='<%= Request.Url.AbsoluteUri.EndsWith("/Poll") ? "selected" : "" %>'>Poll</li>
<li id="liInvite" class='<%= Request.Url.AbsoluteUri.EndsWith("/Invite") ? "selected" : "" %>'>Invite</li>
<li id="liFavourite" class='<%= Request.Url.AbsoluteUri.Contains("/Favourite") ? "selected" : "" %>'>My Favourites</li>
The <li> without runat="server" works fine, when on correct page the source code shows class="selected" or class="" as appropriate, the other <li> used to work fine too, until I decided to add the runat="server".
Once I added that runat="server", the whole block of class="" is being sent out to the html page, its not processing the server tags at all! I right click on the html and look at the source, it's being rendered as:
<li id="ctl00_ctl00_ContentPlaceHolder1_liBlog" class="<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>">Group Blog</li>
It's pouring out my server tags into the source code!
Why is this behaviour seen? How can I avoid it?
I looked up a lot of similar threads in here and there was nearly nothing in google, so made this, I dont think this is a duplicate question.
You can't use the <%= %> syntax inside the properties of tags that have the runat="server" attribute on them.
You either need to:
Set the properties via your code-behind
Create an Expression Builder (and part 2 and part 3) and use the <%$ %> syntax (note: these are links to stuff I wrote on my blog, so, beware the self link =)
for your requirement you can also use ASP.NET menu and XmlSiteMap to do the same thing.