Removing white spaces after writing a file in aspx page - vb.net

I am trying to remove white spaces created after writing file in aspx page. Below is the code for your reference:
<div class="wrapper" runat="server">
<header class="main-header skin-blue">
<%If Session("UserRole") = "Admin" Or Session("UserRole") = "TeamLead" Then
Response.WriteFile("frmHeaderAdmin.aspx")
Else
Response.WriteFile("frmHeaderEmployee.aspx")
End If %>
</header>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar" runat="server">
<%If Session("Userrole") = "Admin" Then
Response.WriteFile("frmSideBarAdmin.aspx")
ElseIf Session("Userrole") = "TeamLead" Then
Response.WriteFile("frmSideBarTL.aspx")
Else
Response.WriteFile("frmSideBarUser.aspx")
End If%>
</aside>`enter code here`
</div>
Please let me know where I am going wrong so that I can make necessary changes in the code

Related

a page can have only one server-side form tag - allow unauthenticated access in aspnet membership provider

I have been given an "old-school" application that uses asp.net membership provider for logins. My aim is to redirect users to "ChangePassword.aspx" page when they try to login - if they have a dirty flag set in the db.
Dim hash As SecurePassword = New SecurePassword()
If Not hash.IsAccountSecurelyUpgraded(myLogin.UserName) Then
Response.Redirect("/aspnet_membership/ChangePassword.aspx")
End If
If Membership.ValidateUser(myLogin.UserName, myLogin.Password) Then
...some code...
End If
I get error
A page can have only one server-side form tag
ChangePassword.aspx
<%# Page Language="VB" AutoEventWireup="false" Inherits="VL.ChangePassword" Codebehind="ChangePassword.aspx.vb" %>
<%# Register TagPrefix="uc1" TagName="Header" Src="../UI/Template/Header.ascx" %>
<%# Register TagPrefix="uc1" TagName="Footer" Src="../UI/Template/Footer.ascx" %>
<uc1:header id="Header1" runat="server"></uc1:header>
<form id="ChangePassword" runat="server">
<h2>Change Your Password</h2>
...
</form>
<uc1:footer id="Footer1" runat="server"></uc1:footer>
Other Urls in the site don't give this error. (they give unauthenticated error)
Site.master
<body>
<div id="wrapper">
<form id="form1" runat="server">
<div id="header">
<span class="title">User Account </span><br />
<span class="breadcrumb">
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
</span>
</div>
<div id="content">
<asp:contentplaceholder id="MainContent" runat="server">
<!-- Page-specific content will go here... -->
</asp:contentplaceholder>
</div>
<div id="navigation">
<asp:ContentPlaceHolder ID="LoginContent" runat="server">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
Welcome back,
<asp:LoginName ID="LoginName1" runat="server" />.
<br />
<asp:HyperLink ID="lnkUpdateSettings" runat="server" NavigateUrl="~/aspnet_membership/AdditionalUserInfo.aspx">Update Your Settings</asp:HyperLink>
</LoggedInTemplate>
<AnonymousTemplate>
Hello, stranger.
</AnonymousTemplate>
</asp:LoginView>
<br />
<asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Logout.aspx" />
<br /><br />
</asp:ContentPlaceHolder>
<ul>...</ul>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" />
</div>
</form>
</div>
</body>
It turned out the header UserControl had scripts added in codebehind.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoginPanel.Visible = Not UserManager.IsLoggedIn()
If System.IO.Path.GetFileName(Request.ServerVariables("SCRIPT_NAME")) = "ChangePassword.aspx" Or
System.IO.Path.GetFileName(Request.ServerVariables("SCRIPT_NAME")) = "RecoverPassword.aspx"
(System.IO.Path.GetFileName(Request.ServerVariables("SCRIPT_NAME")) = "contact.aspx" And Not UserManager.IsLoggedIn()) Then
LoginPanel.Visible = False
End If
If Not Page.IsPostBack Then
Login_Check()
End If
End Sub
After adding, ChangePassword.aspx to the list, it started working

Links do not work after translation into slim format

I have an html code with rails. I need to translate it into slim format, I changed the file format, translated it with a convector and tried to run it as a result the links do not work, can you tell me why?
head.html.erb
<section id="header">
<div class='navigation-panel'>
<button class='burger-button' id='header-burger-button container' onclick='burgerAction()'>
<%= image_tag("header/burger.png") %>
</button>
<button class='contact-us-button burger-hidable container' onclick='scroller("contact")'> CONTACT US </button>
<div class='menu-container burger-hidable container' style='display: none;'>
<%= image_tag("header/menu.png") %>
</div>
<div class='nav-links burger-hidable' style='display: none;'>
<p onclick='scroller("header")'>Home</p>
<p onclick='scroller("services")'>Services</p>
<p onclick='scroller("how-we-work")'>How We Work</p>
<p onclick='scroller("team")'>Team</p>
<p onclick='scroller("why-us")'>Why Us</p>
<p onclick='scroller("portfolio")'>Portfolio</p>
<p onclick='scroller("contact")'>Contact Us</p>
</div>
</div>
</section>
head.html.slim
section#header
.navigation-panel
button.burger-button id=("header-burger-button container") onclick="burgerAction()"
= image_tag("header/burger.png")
button.contact-us-button.burger-hidable.container onclick="scroller(\"contact\")" CONTACT US
.menu-container.burger-hidable.container style=("display: none;")
= image_tag("header/menu.png")
.nav-links.burger-hidable style=("display: none;")
p onclick="scroller(\"header\")" Home
p onclick="scroller(\"services\")" Services
p onclick="scroller(\"how-we-work\")" How We Work
p onclick="scroller(\"team\")" Team
p onclick="scroller(\"why-us\")" Why Us
p onclick="scroller(\"portfolio\")" Portfolio
p onclick="scroller(\"contact\")" Contact Us
I believe the problem is the escaped quotation inside the onclick attributes.
Consider using single quotes inside your attributes' double quotes: onclick="scroller('header')".
You can read more about escaping and quoting attributes here: https://www.rubydoc.info/gems/slim/frames#Output_without_HTML_escaping___

Kentico's webpart control ID in value in a repeater and transformation

I'm building out a bootstrap based accordion. It's almost there, except i need to wrap each accordion with a tab with a unique ID. My thought was to use the repeaters control ID. So how i can access this from a transformation, and also the HTML envelope?
Here is the HTML envelope from the repeater
<div class="accordion" id="askUsAccordion">
</div>
Here is my transformation code
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<%# DataItemIndex + 1 %> <%# Eval("Heading") %>
</h4>
</div>
<div id="accordionPanel<%# DataItemIndex + 1 %>" class="panel-collaspe collapse" role="tabpanel" aria-labeledby="panel<%# DataItemIndex + 1 %>">
<div class="panel-body">
<%# Eval("Panel") %>
</div>
</div>
</div>
Why not just use the Repeater's ClientID?
Try <%# Container.ClientID %> in this case Container should reference the Repeater the transformation is running on.
Mark, not sure this is the best solution, but it should work for you. Add server side function into your transformation like this:
<script runat="server">
protected string GetID()
{
Control parent = this;
while ( (!(parent is CMSWebParts_Viewers_Documents_cmsrepeater)) &&
(parent != null))
{
parent = parent.Parent;
}
return (parent as CMSWebParts_Viewers_Documents_cmsrepeater).WebPartID;
}
</script>
And call this method in your transformation like this:
<%# GetID() %>
While this isn't my preferred method, i wrote a quick js snippet. I try to avoid having too much JS.
/* Accordions */
// we first detect if there is an accordion in the DOM, and if see we ensure that each is with it's own names space
if ($accordion.length){
// we need the ID of each accordion on the page which then becomes the data-parent value, which is needed to ensure we can isolate accordions
$accordion.each(function(i,v){
var $this = $(this),
$id = $this.attr('id');
// loop through each accordion panel
$this.children('.panel').each(function(){
var $that = $(this);
$('.panel-title-link', $that).attr('data-parent', $id);
});
});
}

Razor's Umbraco.media throws error when no image is uploaded

I'm making a bunch of content boxes to render to the master. They all contain a background picture, a heading and content, all are ment to be optional. so if none = empty divs. -> removed.
it all seemed allright i used the #Umbraco.Field for text and #Umbraco.Media(CurrentPage.myMediaAlias).url for the bg picture. Using 'media picker' as datatype.
No problem leaving the heading and content fields blank.
But the problem started when there was no picture defined for the last box.
i got the:
Object reference not set to an instance of an object.
[No relevant source lines]
Since it is supposed to be optional to put in that picture, i would rather want a null back.
The media picker property is not mandatory. How can i get this to work?
#section contentMid2 {
<div class="c-box-wrapper">
<div class="c-box" id="c-box-3" Style="background-image: url(#Umbraco.Media(CurrentPage.box3Bg).Url )" >
<div class="transbox">
<div class="home-head-1"> #Umbraco.Field("mainHeading3") </div>
<div class="content-text1"><p>#Umbraco.Field("mainContent3")</p></div>
</div>
</div>
}
Untested - but something like this should work. They key being to use HasValue
if(#CurrentPage.HasValue("box3Bg"){
<div class="c-box" id="c-box-3" Style="background-image: url(#Umbraco.Media(CurrentPage.box3Bg).Url )" >
}
else{
<div class="c-box" id="c-box-3">
}
OR
#{
var inlineStyle = "";
if(#CurrentPage.HasValue("box3Bg"){
inlineStyle = background-image: url(#Umbraco.Media(CurrentPage.box3Bg).Url )
}
}
<div class="c-box-wrapper">
<div class="c-box" id="c-box-3" Style="#inlineStyle" >
<div class="transbox">
<div class="home-head-1"> #Umbraco.Field("mainHeading3") </div>
<div class="content-text1"><p>#Umbraco.Field("mainContent3")</p></div>
</div>
</div>
</div>
After some debuging and some help from #marco. i realized how to fix it:
<div class="c-box" id="c-box-3" Style="background-image: url(#(Umbraco.Media(CurrentPage.box3Bg.ToString())!=""?Umbraco.Media(CurrentPage.box3Bg).Url:Umbraco.Media(CurrentPage.box1Bg).Url))" >
It's a Shorthand, and still inside the style url: #(theobj!=empty?nah:yah) works like a charm.
But i had to convert theobj .ToString() before comparing or it or else it seems like .Media cant decide if it's int or string. even if the question was if it's nothing in there at all.

vb.net split help required

im currently trying to grab an avatar from an html web source, probllem is theres several img sources and containers that have the same name, heres the current part i need
</div>
<div class="content no_margin">
<img src="http://www.gravatar.com/avatar/4787d9302360d807f3e6f94125f7754c?&d=mm&r=g&s=250" /><br />
<br />
<a class="link" href="http://sharefa.st/user/donkey">Uploads</a><br />
<a class="link" href="http://sharefa.st/user/donkey/favorites">Favorites</a><br />
</div>
</div>
<div id="content" class="left">
<div class="header">
Uploads
</div>
<div class="content no_margin">
<div class="profile_box">
<div class="profile_info">
Now the part i need to grab is:
<img src="http://www.gravatar.com/avatar/4787d9302360d807f3e6f94125f7754c?&d=mm&r=g&s=250" /><br />
this image, Any help and id be grateful!
try:
Dim wb As New WebBrowser
wb.Navigate("")
Do While wb.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
Loop
wb.DocumentText = HtmlString 'Your Html
For Each img As HtmlElement In wb.Document.GetElementsByTagName("img")
If InStr(img.GetAttribute("src"), "avatar") Then
MsgBox(img.GetAttribute("src"))
End If
Next
You appear to be attempting to parse HTML 'by hand'. Please don't.
http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
see this question for some alternatives How do you parse an HTML in vb.net
Use regular expression to find what you're looking for:
http://msdn.microsoft.com/en-us/library/twcw2f1c.aspx
The example code demonstrates pretty much your scenario.