asp.net vb how to make hidden additional attachment hidden and visible? - asp.net

Hi I tried in afew manners but wasnt able to make it work.
I want to make 5 attachment options in that 4 out of the 5 are hidden.
but when he clicks "more attachment" link it will show the other 4.
any ideas?
Im using ASP.NET with VB
plus if you need my code let me know!
thank you!

you can do that with many ways, one of them is enclose your 4 attachments within a div styled with display:none and by using javascript shows them in onclick events of more attachment link, something like this
<div style="display:none" id="moreattchdiv">
<!-- 1st attachment -->
<!-- 2nd attachment -->
<!-- 3rd attachment -->
<!-- 4th attachment -->
</div>
<div onclick="showmore()">more attachments</div>
<script>
function showmore()
{
var moreattachdiv = $('#moreattchdiv');
if(moreattachdiv.is(':visible'))
{
moreattachdiv.hide();
}
else
{
moreattachdiv.show();
}
}
</script>
Note I am using jquery in my script
you can test that example here
Update
insert this line into header tag of your page.If you are using master page insert it into its header tag
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
If you would like to do it without jquery replace the showmore() function with this code
function showmore()
{
var moreattachdiv = document.getElementById('moreattchdiv')
if(moreattachdiv.style.display=='none')
{
moreattachdiv.style.display=''
}
else
{
moreattachdiv.style.display='none'
}
}
you can test it here

You can wrap the hidden 4 attachments in a div that has the style set to display: none, then when you click the more attachments link, it would set the style of that hidden div to display: block.
Here's an example:
http://jsfiddle.net/kmmzH/

Related

How to hide specific element on page from _Layout.cshtml page

I work on mvc 5 project.
On my _Layout.cshtml I have html element named id="topBar" this element displayed in each page.
But I have page named About.cshtml I don't want this page to display only element id="topBar" all other html elements in _Layout.cshtml I want them to be displayed normal in About.cshtml.
Any idea how can achieve described appearance above?
One simple way of achieving this (without javascript), is to set a value in ViewBag inside your about Action and use it in layout like this:
_Layout.cshtml
#if (ViewBag.ShowTopBar ?? false)
{
<div id="topBar">
</div>
}
Action inside your Controller:
public class MyAwesomeController : Controller
{
public ActionResult About()
{
ViewBag.ShowTopBar = true;
return View();
}
}
There are two options:
1. Add an ID to every body element
You could add an ID to the body of each of your pages that contains for example the Controller and Action name and then add a CSS rule to hide the topBar element on the about page.
First, let's create two string variables for the controller and action name. Do this in your _Layout.cshtml:
#{
string controller = ViewContext.RouteData.Values["controller"].ToString();
string action = ViewContext.RouteData.Values["action"].ToString();
}
Next, add the ID to the body:
<body id="#controller-#action">
In your css, you can now add a rule to hide the topbar in the about page (assuming the controller is called HomeController):
#Home-About #topBar {display:none;}
You could also use an extension method to get the controller and action name. For example something like this.
2. Use jQuery on the About page
You could add a Javascript on your about page and use jQuery to hide the topbar (I assume jQuery is already loaded):
<script>
$("#topBar").hide();
</script>
Easier way, just did that: style your page individually:
<style>
#showcase { display: none; }
</style>
Put this on the page that you want to hide, showcase is my section id. ;)

I want to enable text box on image click in asp using java script

I want to enable text box on image click in asp using java script initially my text box is disable
As you have added no markup to your question so i am assuming an Image and writing an example of how to disable/enable with Javascript
<html>
<body>
// Image
<img src="\URL" onClick="EnableTxt()" />
<script>
// Javascript Function
function EnableTxt() {
document.getElementById( '<%=txtBox.ClientID%>' ).disabled = 'false';
}
</script>
</body>
</html>

Control one iFrame from another iFrame

This works …
Link text
but this doesn't …
<script type="text/javascript">
window.onload = function() {
var a = document.getElementById("mylink");
a.onclick = function() {
parent.document.getElementById('frameName').src = 'page.html';
}
}
</script>
<a id="mylink" href="page.html">LINK</a>
Any idea why I can't get the element by id from one iFrame to another? Also I know very little code so I apologize in advance if its obvious.
First i would make sure that the security of the site within the IFrame allows you to do this kind of stuff. Check out this link:
Overcoming "Display forbidden by X-Frame-Options"
Next, i would worry about the target of your anchor tag. With specifying it will default to self. In your second piece of code the target will be _self. Thus, when you click the link your javascript will want to change the source of the IFrame while the link will want to change the entire page. I would pick either a JS or HTML implemetation of linking and not both. Here is something that i put together to show one way of changing the iFrame without an actual anchor tag.
<html>
<body>
<iframe id="frameName" src="page.html"></iframe>
<button onclick="changeFrame()">LINK</button>
<script>
function changeFrame() {
document.getElementById('frameName').src ='page2.html';
}
</script>
</body>
</html>

MaintainScrollPositionOnPostback is not working - how to debug?

I inherited some web shop project (ASP.NET 3.5, Webforms, Visual Studio 2008 PRO).
On one page I have MaintainScrollPositionOnPostback set to true.
When shopping cart (user control loaded in master page) is empty, then asp.net is not generating Javascript code required for scroll position. When I add some items to the cart, then everything works fine.
Can you give me any advice how to find part of the code which is responsible for this issue?
I don't have an access to the 3rd party profilers.
Are you utilizing UpdatePanels in that specific page?
If Yes, following article may give you some direction:
http://basgun.wordpress.com/2008/06/09/maintain-scroll-position-updatepanel-postback/
If No, this one may assist:
Javascript: Maintaining Page Scroll Position
Here is the code from that article:
// function saves scroll position
function fScroll(val)
{
var hidScroll = document.getElementById('hidScroll');
hidScroll.value = val.scrollTop;
}
// function moves scroll position to saved value
function fScrollMove(what)
{
var hidScroll = document.getElementById('hidScroll');
document.getElementById(what).scrollTop = hidScroll.value;
}
</script>
</head>
<body onload="fScrollMove('div_scroll');" onunload="document.forms(0).submit()";>
<form>
<input type="text" id="hidScroll" name="a">< /br>
<div id="div_scroll" onscroll="fScroll(this);"
style="overflow:auto;height:100px;width:100px;">
.. VERY LONG TEXT GOES HERE
</div>
</form>
</body>
</html>
Hope one of these links help!

Enter button does not submit form (IE ONLY) ASP.NET

I have a form with a textbox and a button. IE is the only browser that will not submit the form when Enter is pressed (works in FF, Opera, Safari, Chrome, etc.). I found this javascript function to try to coax IE into behaving; but no avail:
function checkEnter(e){
var characterCode
if (e && e.which) {
e = e
characterCode = e.which
} else {
e = event
characterCode = e.keyCode
}
if (characterCode == 13) {
document.forms[0].submit()
return false
} else {
return true
}
}
Implementation:
searchbox.Attributes("OnKeyUp") = "checkEnter(event)"
Any advice?
EDIT: This page on CodeProject outlines what Dillie was saying, and it works perfectly.
Just create a text input in a hidden div on the page. This will circumvent the IE bug.
Example div:
<!-- Fix for IE bug (One text input and submit, disables submit on pressing "Enter") -->
<div style="display:none">
<input type="text" name="hiddenText"/>
</div>
The other thing I have done in the past is wrap the form area in a Panel and set the DefaultButton attribute to the submit button you have. This effectively maps the enter key to the submission as long as you have a form element in focus in the panel area.
There is a good write up of this problem here, and a nice jquery based solution:
http://www.thefutureoftheweb.com/blog/submit-a-form-in-ie-with-enter
// Use the following Javascript in your HTML view
// put it somewhere between <head> and </head>
<script language="JavaScript" type="text/javascript"><!--
function KeyDownHandler(btn)
{
if (event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
btn.click();
}
}
// -->
</script>
// Put this in your TextBox(es) aka inside <asp:textbox ... >
onkeydown="KeyDownHandler(ButtonID)"
When using display:none, IE won't see the button and therefore won't be able to use it to submit the form. Instead, you could use z-index and absolute positioning to hide it under another element, e.g. with the style:
position:absolute; bottom: -20px; left: -20px; z-index: -1;
Now it'll still be there, usable by IE, but hidden beneath another element.
Hide the button - not using display:none, but with the following styles:
position: absolute; /* no longer takes up layout space */
visibility: hidden; /* no longer clickable / visible */
If you do this, you won't need to add any other elements or hidden inputs.
This is due to a peculiarity in IE for single text field inputs.
A simple solution is to stop the page having a single text field by adding another hidden one.
<input type="text" name="hidden" style="visibility:hidden;display:none;" />
see..
https://web.archive.org/web/20210125133120/https://www.4guysfromrolla.com/articles/060805-1.aspx
Does it use a GET instead of a POST? Is the URL too long? I've seen that...
Basically, a form needs either a button, input type="submit" or an input type="image" to enable the builtin behaviour to submit a form on enter. You shouldn't need a javascript to submit it.

Resources