ASP content display issue - asp-classic

I moved my site to another hosting, but the language menu <a> tags between the content of the database does not print between the label. But inside the href parameter it draws the same query.
When I examined the output of the code:
Output code picture
Below is my code in that line:
<ul class="headerLanguage"><li><%=Session("lang")%><img alt="" title="" src="/images/icon/08.png" /><ul><%
Set a = SQL.Execute("SELECT kisa FROM diller WHERE kisa<>'"& Session("lang") &"'")
Do while not a.Eof %><li><%=a("kisa")%></li><% a.MoveNext:Loop
a.Close
Set a = Nothing %></ul></li></ul>
When I delete the query inside the href parameter, the other query runs and the content is appearing.
My application is Classic ASP, but I did not have a problem with my old site, why was this so? How can I solve?
I'm grateful for your help.

I've encountered this problem before. I'm not sure exactly why it happens (hopefully someone else can explain), but sometimes if you reference data directly from a recordset multiple times it can return an empty value. The solution that worked for me was to assign the data to a variable first and reference the variable instead. Try this:
<ul class="headerLanguage">
<li>
<a href="/?lang=<%=Session("lang")%>"><%=Session("lang")%>
<img alt="" title="" src="/images/icon/08.png" />
</a>
<ul><%
Dim a, kisa
Set a = SQL.Execute("SELECT kisa FROM diller WHERE kisa<>'"& Session("lang") &"'")
Do while not a.Eof
kisa = a("kisa") %>
<li><%=kisa%></li><%
a.MoveNext:Loop
a.Close
Set a = Nothing
%></ul>
</li>
</ul>

Related

When I try to use to redirect to another screen through master page this error happening

When I click on link from master page I got this issue .How can I fix this issue
</a><a href="vacations.aspx">
<div class='<%= vacDetailMenu %>' style="cursor: pointer;">
Vacation History
</div>
This is the code which I used.
This is the issue:
"Index and length must refer to a location within the string.
Parameter name: length"
Can you please share your more code .. .
this is a error which comes when you put string length more than Real length,
string muString="Hello";
string substring = myString.Substring(0, 6);
and
</a><a href="vacations.aspx">
is not Proper Anchor Link , You should use it like
SomeText

How to build an infinite tree hierarchy?

I've been working on this since yesterday and I'm completely stumped. I'm working in VB.NET but I can understand C# if you'd prefer to answer it that way.
Basically I have items from a SQL database with IDs and parent IDs and I need to put them in a tree like so:
<ul>
<li>Some item
<ul>
<li>Another item
<ul>
<li>This could go forever
<ul>
<li>Still going</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
Currently I have a nested repeater which works but it only gets me to the second level. It looks something like this:
<asp:Repeater ID="parent" runat="server">
<ItemTemplate>
<ul>
<li><span><%#Container.DataItem("Name")%></span>
<asp:Repeater ID="child" DataSource='<%#CType(Container.DataItem, DataRowView).Row.GetChildRows("relation")%>' runat="server">
<ItemTemplate>
<ul>
<li><span><%#Container.DataItem("Name")%></span></li>
</ul>
</ItemTemplate>
</asp:Repeater>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
The relation is like this:
ds.Relations.Add("relation",
ds.Tables("Items").Columns("ID"),
ds.Tables("Items").Columns("ParentID"),
False)
I understand why it won't work because it doesn't have a template to continue the tree. So I'm trying to figure out a way around that.
I've considered writing a function to just build the string in the code behind and stick it in the html with an asp tag. I wasn't sure how to go about this while pulling the data out of the database.
I found a temporary solution though it's extremely inefficient. In case anyone stumbles across my question this will at least get you by. For large amounts of data it could take up to a full minute to load.
If anyone could comment on how to make this more efficient that would be nice.
Code behind:
Private Dim dt As New DataTable
Public Function BuildTree(ByVal ID As String) As String
Dim sb As New StringBuilder
dt = YourDatabase.GetChildren(ID) '<-- You'll have to write this function
sb.AppendLine("")
If dt.Rows.Count > 0 Then
sb.AppendLine("<ul>")
If dt.Rows.Count > 1 Then
For Each row As DataRow In dt.Rows
sb.AppendLine("<li>" & row("ItemName"))
' Recursive call
sb.AppendLine(BuildTree(row("ID").ToString))
sb.AppendLine("</li>")
Next
Else
sb.AppendLine("<li>" & dt.Rows(0)("ItemName").ToString & "</li>")
End If
sb.AppendLine("</ul>")
End If
Return sb.ToString
End Function
Then in your aspx page do something like this:
<%#BuildTree(Container.DataItem("ID").ToString)%>
EDIT: Declaring the DataTable outside of the function helps the efficiency a bit.

actionlink manipulates html render order in nested anchor

I'm having a problem and i'm really puzzled by it.
My markup is simple enough:
#foreach (var item in Model.Items)
{
<a class="mapIconUnit" id="pinDelete-#item.PinGuid.ToString()">
#Url.Action("DeletePin") <!-- testing purposes -->
#(Ajax.ActionLink("x", "DeletePin", MapAdministrationController.Routes.DeletePin(item.PinGuid), new AjaxOptions()
{
OnSuccess = "onMapPinDeleted",
Confirm = Resources.Resource.msg_GenericDeleteConfirmationQuestion
}
))
</a>
}
Now what i would expect to render from this is:
<a class="mapIconUnit" id="...">
... rendered url
<a href="..." etc>x</a>
</a>
But what i am getting is:
<a class="mapIconUnit" id="...">
... rendered url
</a>
<a href="..." etc>x</a>
What am i doing wrong here? The markup is too simple for it to be wrong to cause such a thing?
It's illegal to nest an anchor element inside another anchor element, more info can be found in the W3C specs: http://www.w3.org/TR/html401/struct/links.html#h-12.2.2
Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements.
So either razor or the webbrowser renders the elements correctly (i.e. place them next to each other).

show/hide css menu item depending user role using asp.net

I have the css layout: One column fixed width layout, from maxdesign.com
I have two menu items defined like the following:
<div id="navigation">
<ul>
<li>Data Entry</li>
<li>Reports</li>
</ul>
</div>
Now, let's say that I have two roles: guest and operator, and I want that for example if a user with role guest is logged in, then just the Report item from the menu appear, and in case of a user operator is logged in, then both options appear.
How can I accomplish that?
EDIT:
Based on your responses, I'll go with the server side logic to deal with this:
<div id="navigation">
<ul>
<li><asp:LinkButton ID="lkbDataEntry" runat="server">Data Entry</asp:LinkButton></li>
<li><asp:LinkButton ID="lkbReports" runat="server">Reports</asp:LinkButton></li>
</ul>
</div>
Thanks!
You can put this in the Page_Load..
Dim cs As ClientScriptManager = Page.ClientScript
If Not cs.IsClientScriptBlockRegistered(Me.GetType(), "RoleVariable") Then
Dim js As New String
js = "var _role = " & role & ";"
cs.RegisterStartupScript(Me.GetType(), "RoleVariable", js, True)
End If
And from there, you will have the role in the Javascript realm, where you can manipulate the visibility of the items you want.
So...
<script type="text/javascript">
function hideStuff() {
if (_role === "operator") {
// hide/show your elements here
}
else if (_role === "guest") {
// hide/show your elements here
}
}
</script>
Keep in mind that this approach is all client-side and is therefore easy for another developer to manipulate if they really wanted to. But on the other hand, it's the simplest. Don't use this approach for high-security situations.
You could give your menu elements an ID attribute and then in your codebehind either use RegisterClientSideScriptBlock or use Response.Write to send JavaScript to the client to hide (or show) elements based on some condition.
how about something simple like?
<% if(Page.User.IsInRole("operator") || Page.User.IsInRole("guest")) { %>
<div id="navigation">
<ul>
<% if(Page.User.IsInRole("operator")) { %>
<li>Data Entry</li>
<% } %>
<li>Reports</li>
</ul>
</div>
<% } %>
I don't 100% think you can (or should) be doing logic operations with stylesheets. You may need to have some javascript and then decide based on guest or operator which style to display

If / Else condition with OR clause not working in Classic ASP

I am checking if condition in Classic ASP but its not working properly. Here is the code that isn't working:
<% If (Request.QueryString("Cat")="") Then %>
<a class="home selected" href="/" alt="Home"></a>
<%Else%>
<a class="home" href="/" alt="Home"></a>
<%End If%>
This displays both anchor tags but I want to display only one from both.
Please give me suggestions on how to fix it.
Sean has taken is a step in the right direction but but this is some include asp isn't it, providing some kind of common navigation bar. Consider this approach.
<%
''# Some where at the top of the include we have a set of utlity functions
Function GetSelectedClass(cat)
If (Request.QueryString("Cat") = cat) Then
GetSelectedClass = " selected"
End If
End Function
''# Other utility functions here
%>
<!-- Here we start the common navigation HTML -->
...
<a class="home <%=GetSelectedClass("")%>" href="/" alt="Home"></a>
<a class="tables <%=GetSelectedClass("tables")%>" href="/List.asp?Cat=tables" alt="Tables"></a>
<a class="chairs <%=GetSelectedClass("chairs")%>" href="/List.asp?Cat=chairs" alt="Chairs"></a>
While I don't see any issue with the code that is posted, I cleaner way of doing this:
<%
Dim Cat, Selected
Cat = Request.QueryString("Cat")
If (Cat = "") Then
Selected = " selected"
End If
Response.Write("<a class=""home" & Selected & """ href=""/"" alt=""Home""></a>")
%>

Resources