I used multibox-component to create lightbox-similar div. But I faced problem. I placed textbox with id ‘tbx_position’ in that div. I entered some symbols in textbox and then tried to read value via javascript-function (it had to alert document.getElementById(‘tbx_position’).value). Every time that value was empty.
There is example of it.
Furthermore, if I place in the div asp:Button, server OnClick-eventhandler doesn’t catch fire.
Is any idea, what’s reason? Thanks.
Try adding the <form> & </form> tags to your page.
Related
I am trying to hide an aspx button on page load if another element has a certain value.
Button:
<input type="button" class="formButton" id="btnShowTerminate" value="Terminate Credential" onclick="ToggleTerminationRow()">
My issue is that I don't know how to edit the buttons attributes (to make it hidden) in the code behind.
In code behind (on PageLoad event):
Page.btnShowTerminate.Visible = false;
HTML controls need to be given the runat="server" attribute in order to be used in the server-side code.
To hide the button from your code behind, use an If statement to test if your 'other element' has the required value.
C#
If(exampleElement.Value == "example value")
{
Page.btnShowTerminate.Visible = false;
}
VB
If exampleElement.Value == "example value"
Page.btnShowTerminate.Visible = false;
End If
This error -
'System.Web.UI.Page' does not contain a definition for
'btnShowTerminate' and no extension method 'btnShowTerminate'
accepting a first argument of type 'System.Web.UI.Page' could be found
(are you missing a using directive or an assembly reference?
is because you haven't included runat="server" in your input.
The exampleElement.Value may have to be different depending on what type of element exampleElement is. For example, Value will work with a TextBox , but you would need to use InnerHtml for a div
Although, a button (any control for that matter) can be hidden from code behind by setting the Visible property to false, there is subtle, and dangerous nuance to that. Doing this causes the button not only to be hidden, but the resulting HTML button will not render on the page. Should you have JavaScript that is referencing the button, the JavaScript will fail because the button does not exist on the rendered page. In debugging, the bug will be caught, but if the JavaScript is never exercised until the code is deployed to a server, it will fail there but no exception will be thrown. The code just won't work and there will be no indication as to why!
The safe way to hide the button is setting the Style as follows:
btnName.Style.Add("display", "none");
This way the button will be rendered but hidden and JavaScript will be able to find it.
So I have an input box in a custom pop up div that is in a hidden div on the page until the user clicks on something activating the pop up box. When the user clicks we get the html of the hidden div and add it to our popup box div which is located in the master page(MVC.)
<input type="text" id="from" name="from" value="MM/DD/YYYY" style="width: 90px;" />
If I change this field and run a script on the submission of the form
var fromDate = document.getElementById("from").value;
I still get the MM/DD/YYYY Default value and not the value I entered. Even more oddly I did an onchange event on the from field and I still get MM/DD/YYYY.
Any help would be greatly appreciated, I have no idea whats going on. Could it be that it's still fetching the value from the hidden div?
Don't you mean
document.getElementById("from").value
instead of
document.getElementById("to").value
I hope your code should have been like
var fromDate = document.getElementById("from").value;
I was filling this temporary element with a hidden div on the page. Because of this I was not returning the value in the temporary pop up but, instead, the value in the hidden div. I needed to rearrange to get it to work.
OK, first some background: I have a page showing the number of hits(or views) of any selected item. The hit counter procedure that is called at every page load i.e
if (Request.QueryString.HasKeys())
{
// get item id from icoming url e.g details.aspx?itemid=26
string itemid = Request.Params["itemid"];
if (!Page.IsPostBack)
{
countHit(itemid);
}
}
The problem: my expectation was that the counter would be increased by 1 on every page load but the counters on my datalist and formview are always behind and stepped by 2 i.e
instead of 1, 2, 3, 4, it's 0, 2 , 4, 6.
It seems that the page load is firing twice. Later I discovered that this only happens when you are using Mozilla Firefox. The page behaves fine with other browsers like IE
This becoming quite frustrating.
I've seen Page_Load fire twice if you have an <asp:Image> or an <img runat="server"> on the page that doesn't have its src attribute specified.
Could be worth a look.
I am aware of following things.
If you have img control with empty string assigned to src attribute.
You may be forgot to assign imageurl or wanted to assign imageurl in code behind based on the some condition and that condition never gets executed and ended up being empty string assigned to src attribute when ASP.Net renders the page.
If you have empty string assigned to href attribute to html link for stylsheet.
If you have empty src attribute set to script.
for more information refer this article. http://patelshailesh.com/index.php/page_load-event-fires-twice-with-firefox-only
I had this problem as well.. in my case firebug was causing the extra call.
We ran into a similar problem where fiddler showed that one of our pages loaded twice. This only happened in Firefox and Chrome. The solution was to change:
background-image:url('');
to
background-image:none;
Try turning off FireBug if you have it enabled.
I had this problem too. I found that AVG antivirus toolbar on firefox makes another hit to that page and I had 2 hits per refresh.
Just go to Tools>Add-ons and disable AVG toolbar if you have it. Otherwise it may caused by another extension like one added by antiviruses or other software.
Good luck
The most likely reason is that you're calling the procedure twice.
Usually the reason that the page_load is fired twice is that you have AutoEventWireup=true in the ascx/aspx AND you bind the Load event to the Page_Load method explicitly (in the codebehind).
But then you should see this behavior in all browsers.
Anchor tag with empty href i.e. href="" is also an issue. Use href="#" wherever URL is not required in an anchor tag.
I have this linkbutton with post-back disabled ... I should have done it with an html control but just did it that way .. It is toggling a language bar on top (marara.com.tr - language link)
It needs to be clicked twice in order to get the div to fade-in. I can correct the problem but just want to know why it behaves like that. .. in the first click it adds a # sign to the address bar then on the second click it does what it is supposed to.. any leads?
thanx in advance
Emre
I had a similar problem. It depends on the browser you are using (This occurred when I was using Firefox but not when I was testing in IE6). It seemed like the browser looks at the URL and sees that nothing has changed (except the #...) so it doesn't reload the URL, causing the #... not to register. You can trick it into thinking the query string has changed by adding a '&' before the '#' so that you add &#... to the URL.
Question: Is there any reason Autocomplete=off on a ASP:Textbox would not be working in IE 7?
In case this is the best term for it, the IE Autocomplete feature is that drop down list like thing that drops down from textboxes and shows you past things you have typed in.
I need the IE Autocomplete feature to not work at this point for a textbox that is part of a user control that works like an Ajax Autocomplete control. Problem is, when the Ajax Autocomplete selection list shows up, so does the IE Autocomplete selection box. (In cases where I might double click the textbox) I'm using this:
someTextbox.AutoCompleteType = AutoCompleteType.Disabled;
But it stills shows up. I've tried removing the items from the IE Autocomplete, but the next time I type something in and press enter, the problem reappears. Any ideas?
Note: The textbox is rendered with the Autocomplete=off tag when viewing the source.
Note 2: Have tried someTextbox.Attributes.Add("autocomplete", "off"); also without success
* Update, figured it out a while ago but forgot *
test.AutoCompleteType = AutoCompleteType.None;
That actually works. I'm not sure what the difference is though. Suppose Ill look that up sometime.
Try adding AUTOCOMPLETE="off" to your form tag too:
<form name="form1" id="form1" method="post" autocomplete="off">
Trying to clear out my unanswered questions that I've answered in the original post.
test.AutoCompleteType = AutoCompleteType.None;
Try this one:
someTextbox.Attributes.Add("autocomplete", "off");
in Page Load
txtusername.AutoCompleteType = AutoCompleteType.Disabled;