How to assign control's position? - asp.net-mvc

i have xml file created in other asp.net project,these file include some controls and their attributes.i need to show those controls on my mvc project,
xml file format may be like below.
<div style='left:84px;top: 50px;' ><input id='Text1' type='text' value='Mr.Temp'/></div>
<div style='left:8px;top: 50px; position: fixed;' >Name</div>
<div style='left:84px;top: 650px;' ><input id='Text1' type='text' value='30'/></div>
<div style='left:8px;top: 65px; position: fixed;' >Age</div>
<div style='left:84px;top: 90px;' ><input id='Text1' type='text' value='Singapore'/></div>
<div style='left:8px;top: 90px;' >Address</div>
i need to show these controls depend on their type and location like this.
Name Mr.Temp
Age 30
Address Singapore
So,i read xml file and write ,my problem is i can create controls based on their type,but i don't know how to
assign their position correctly?Their old location can't use any more because mine is asp.net mvc project.
Give me right way,please.
regards
Indi

Have you considered using xslt? Then you can write rules around all that.
Or, if you don't want to use xslt, then consider using jQuery and write your own plugin to look through your xml and transform that to html.
edit
Well with a plug in you can check out how to write a jQuery plugin here.
Essentially what you'll be doing is giving the xml to the plugin and then the plugin will generate the html for you.
It's a bit too involved for here but you can "each()" on the div, store the first one, then the second and generate html for the pair then move to the next two.
$(xmlDoc).find("div").each(function(){
//this will get each div. now you need to create html for each and return the
//whole as a string to be rendered.
});

Related

How do I conditionally parse formatting with Thymeleaf?

Is there an alternate way I can get this to process with Thymeleaf? Thymeleaf doesn't like the open tag, but I want to only render it for ROLE_A.
<span sec:authorize="hasRole('ROLE_A')">
<div class="col-xs-10">
</span>
bunch of text not specific to ROLE_A
<span sec:authorize="hasRole('ROLE_A')">
custom text specific to ROLE_A
</div>
</span>
I tried using
<sec:authorize="hasRole('ROLE_A')">
and
<div sec:authorize="hasRole('ROLE_A')">.
The former also doesn't run due to the same open tag issue and the latter is mixing up the closed div tags.
I have numerous blocks like this, so duplicating sections for different roles is not a great solution.
Not in the style you want. You need to close those elements.
My advice is then consider using fragments and load them as required with the needed data/
That way you reuse existing code thus making it cleaner and smaller.
For more examples and way you can do the above check out the Thymeleaf page http://www.thymeleaf.org/doc/springsecurity.html.

Dart: dynamic redirection without reload

Please note I'm not interested in a Polymer-, Angular- or route-based solution here. I'm trying to learn "pure" Dart here, and while I'll likely switch to using one of those frameworks down the road, I need to have a good understanding of the fundamentals first.
In Dart, is it possible to download a whole bunch of HTML "snippets" (see below) all at once (at app startup), and then load them into the browser (either the entire window or just inside a particular <div> element, etc.) dynamically?
For instance, my HTML file might have a <div> element:
<body>
<!-- lots of HTML -->
<div id="container"></div>
<!-- more HTML -->
</body>
And I would like to download two "snippets" (DOM subtrees, HTML templates) of HTML, and dynamically load either one of them into the container div tag. Perhaps one of the snippets looks like this:
<h1>I'm Snippet #1!!!</h1>
<input type="button" name="redPillButton" value="Red Pill!" />
And another snippet my look like:
<h1>I'm Snippet #2!!!</h1>
<input type="button" name="bluePillButton" value="Blue Pill!" />
Can the two snippets be inside their own HTML file, or do I have to put them inside one big file and extract out the "snippet" that I want to load? Either way, how do I accomplish this in a Dart web app?
You can keep each parts in their own file and load them like that :
HttpRequest.getString("part.html").then((html) {
querySelector('#container').innerHtml = html;
});

Referring to current HTML-Element in Razor?

In Razor (MVC 4) can I do something like the following (pseudo)code?
<div id="One" #if(THIS_ID_IS("One")) {WRITE_SOMETHING_HERE} ></div>
<div id="Two" #if(THIS_ID_IS("One")) {WRITE_SOMETHING_HERE} ></div>
My intention is, that in DIV "One" an additional attribute will be written, but not in DIV "Two"
So, the THIS_ID_IS(string id) should determine, if the Razor-Parse is INSIDE the given DIV with id="xyz"
Is this possible?
You can use single line if statement to overcome this situation
<div id="One" #(THIS_ID_IS("One") ? "write something" : "") ></div>
Since ids are unique values. All divs will have diffrent ids.
So I dont think there is any need for Conditional Check in razor.
You can Directly add the extra attributes to your Div as follows
<div id="One" attribute-name="Value"></div>
In situations like this I tend to write a helper method to output the markup. This way you a not constrained by the 'rules' of razor. I did a similar thing to output jQuery slider html inside a div.
It also depends on your target audience, I rarely produce the actual views as our designer does most of that. I don't like handing over stuff to the 'creatives' that requires them to write/understand the logic.
It may not be the ideal solution or maybe even overkill in your situation but may be worth a look.
http://www.asp.net/mvc/tutorials/older-versions/views/creating-custom-html-helpers-cs
As much as I would like it to be possible. It looks like it's not the case.
Based on these two articles :
Simple
In depth
It would seem that the Razor engine combines a code and a markup parser.
The main parser decides to use one or the other.
So the parsers are not aware of one another.
Simply put, in your example, <div id="One"></div> and #if(THIS_ID_IS("One")) would be parsed in different scopes and then just concatenated together.

How to loop through properties in a tab and display them using Razor?

I have a Document Type, that has a tab with some properties.
The properties are Upload types, and Simple Editor types.
(Users are supposed to upload images with some image text).
I have not grouped the "Upload" and "Simple Editor" properties, so how do i do this?
Next question,
I want to loop through each group (there should be 3 currently) and display them on my website.
The markup should look like the following:
<div>
<img src="PATH-TO-UPLOAD-TYPE" />
<div>"TEXT FROM SIMPLE EDTIOR TYPE"</div>
</div>
..
<div>
<img src="PATH-TO-UPLOAD-TYPE" />
<div>"TEXT FROM SIMPLE EDTIOR TYPE"</div>
</div>
...
I would like to use Razor for this. Thanks in advance!
For the first part, using the Razor model, you can't. The content object that you get on the front end only contains the properties, the tabs are not included, as they're only really for organising things in the back office.
You CAN get that information using the Umbraco API, but it's pretty database intensive and could potentially be quite slow if you have a lot of properties/tabs.
You'd be better grouping them yourself in your Razor Macro.
for the second part, you can acces the properties of a page via #Model.property. For example:
<div>
<div>#Model.simpleProperty</div>
</div>

Determine an absolute url to a resource using vbscript/classic asp

I've created a pseudo user control for a site written in classic asp. The control is simply an asp page (with full HTML headers and body) that resides within an iframe in the parent page. The point was to create an AJAX-like interface for uploading files asynchronously (the parent page contains a large form and I didn't want to have to upload the files and submit the rest of the form at the same time).
The problem is, I'm running into a lot of issues with relative urls being used in the iframe page/user control. Depending on what page the iframe is a child of, the relative url base location seems to change according to the directory that particular page is in.
Example:
www.website.com/directory1/application1.asp
...
<form>
<input>
...
<iframe src="../controls/FileUpload.asp"/>
...
</form>
...
www.website.com/directory1/directory2/application2.asp
...
<form>
<input>
...
<iframe src="../../controls/FileUpload.asp"/>
...
</form>
...
www.website.com/controls/FileUpload.asp
...
<form method="post" enctype="multipart/form-data" action="FileUpload.asp"><!--problem here-->
<input type="file">
<input type="submit"/>
</form>
The iframe src paths work correctly (notice the one that's buried a directory deeper has an extra double dot). But in the code for the FileUpload.asp page, relative URLs don't work consistently. The URL I have in the action attribute for the form tag works if you simply load the page as-is, not in an iframe of another page. You can change it to "../controls/FileUpload.asp" and it will work on the first application page, but you have to add another "../" for it to work on the second application page.
I was wondering if maybe there's a way with vbscript to find the absolute URL to a certain file. I do use an include file into which I could hard-code this, but I'd rather not if that's possible. Any other ideas?
You could also just put in an absolute path from the root such as
action="/controls/FileUpload.asp"
I'm not sure if you are perhaps looking for
<%
Response.Write Server.MapPath("./foo.txt")
%>
Some usefull code from Thorarin
that I just saw in a different post
Look for ThisPage() Function

Resources