Solved

Swapping of controls on a web form (mirror image) (ASP.NET)

Posted on 2004-10-20
9
182 Views
Last Modified: 2010-04-06
HI All!!
 I am developing an application in ASP.NET (code behind VB.NET) and one of the main functionality of the page is that on clicking of a button on the page, a mirror image of the page is shone (all the controls on the page are swapped eg. All controls from right to left will now be left to right).
 Could you pls give me the codes for doing this? it would be great if I could get codes in VB.NET
0
Comment
Question by:mim_jr
9 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 125 total points
ID: 12374812
When you generate the page give the body an id:

<body id="bod">

Then the control looks like this:

<input type="button" value="mirror image"
onclick="document.getElementById('bod').style.direction='rtl'">


Cd&
0
 
LVL 5

Expert Comment

by:crimson117
ID: 12386663
Do you mean make the text you enter have its direction reversed, or do you mean:

[button1] [button2] [input3]

when you click the switch button/link, it becomes:

[input3] [button2] [button1]

?

You could probably use a div around each form element, then position each div with CSS.  

   <div class='css_class1' id='div1'><input type='text'></div>

When you want to reposition the fields, use javascript:

   div1.class='reversed_css_class1';


Note: this wouldn't be very scalable - you'd have to change the code if you changed the number of elements on the page.

A better implementation would be to parse the DOM of the page, then rewrite it with the form elements in backwards order, but I'm not a DOM expert so css is how I'd do it :-)

And actually, if you're of the "css=layout" "html=data" school of thought, then my first solution is actually better than messing with the DOM with javascript.
0
 
LVL 2

Expert Comment

by:udayms
ID: 12387053
I think COBOLdinosaur's answer would solve your issue
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mim_jr
ID: 12387321
Thank !! well yes i want it 2 b like ..
[button1] [button2] [input3]

when you click the switch button/link, it becomes:

[input3] [button2] [button1]

Can you pls let me know the contents of the 'reversed_css_class1'...
....
I will also try the solution given by  COBOLdinosaur's today... thanks to all
0
 
LVL 5

Expert Comment

by:crimson117
ID: 12388718
As I said, this isn't very scalable, but it works:


<html>
<head>

<style type="text/css">
.boxleft
{
position: absolute;
top: 100px;
left: 50px;
background-color: blue;
color: white;
}

.boxmiddle
{
position: absolute;
top: 140px;
left: 100px;
}

.boxright
{
position: absolute;
top: 180px;
left: 150px;
background-color: red;
color: black;
}

}
</style>

</head>

<body>
<input size=10 id="aa" type="text" class="boxleft" value="a">
<input size=10 id="bb"  type="text" class="boxmiddle" value="b">
<input id="cc"  type="button" class="boxright" value="c button">

<input type="button" value="orig" onclick="javascript:aa.className='boxleft';cc.className='boxright';return false;">

<input type="button" value="switch" onclick="javascript:aa.className='boxright';cc.className='boxleft';return false;">


</body>
</html>

0
 
LVL 5

Expert Comment

by:crimson117
ID: 12388767
Actually cobols works pretty darn well too, as long as you don't have elements positioned with CSS:

<html>
<head>

<style type="text/css">
.boxleft
{

background-color: blue;
color: white;
}

.boxmiddle
{
color: purple;
font-weight: bold;
}

.boxright
{

background-color: red;
color: black;
}

}
</style>

</head>

<body id="bod">
 <input size=10 id="aa" type="text" class="boxleft" value="a">
<input size=10 id="bb"  type="text" class="boxmiddle" value="b">
<input id="cc"  type="button" class="boxright" value="c button">

<input type="button" value="orig" onclick="document.getElementById('bod').style.direction='ltr';return false;">

<input type="button"  value="switch" onclick="document.getElementById('bod').style.direction='rtl';return false;">

</body>
</html>


If you have elements positioned with CSS, the CSS will override the style.direction, and instead only the text-direction inside the input boxes will change.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 12389870
>>>If you have elements positioned with CSS, the CSS will override the style.direction, and instead only the text-direction inside the input boxes will change.

Break the inheritance; of course.  If you have cascades, you have to maintain them.  It is no different for any CSS property they have scope, contraints and inheritance characteristics.


You can scope it from a single element to a page, and you can overlay the styles to ge twhatever effect you want.  That is a primary reason for using CSS.

Cd&
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question