Page load fires twice on Firefox - asp.net

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.

Related

Selenium and iframe

I have an iframe that gets loaded when i click on a tab on a page. When i use Firebug to look at the iframe on IE8, all i see is:
iframe id=tabContextFrame class=contextFrame contentEditable=inherit src=/xyz.dt?forward=show&layouttype=NoHeader&runid=1234 name=tabContextFrame url=/xyz.dt?forward=show&layouttype=NoHeader&runid=1234 scrolling=auto
and that's it.The hierarchy below the iframe can't be seen. I want to click on a link within the iframe. To find the elements within the iframe, I did a selenium.click("on the tab that loads the iframe") and then selenium.getHtmlSource(). From this source, I can at least locate my link of interest. I did a selenium.click("//span[text()='Link']") but it doesn't seem to do anything. Any ideas please?
Here is the code:
selenium.click("//span[text()='tab that loads iframe']");
Thread.sleep(5000);
selenium.selectFrame("tabContextFrame");
selenium.mouseOver("//span[text()='Link']");
selenium.mouseDown("//span[text()='Link']");
selenium.mouseUp("//span[text()='Link']");
Thread.sleep(5000);
selenium.selectFrame("null");
I'm guessing you are using Selenium 1.0. Have you looked at Selenium 2.0 and WebDriver. I found the following and it worked for me:
Q: How do I type into a contentEditable iframe? A: Assuming that the
iframe is named "foo":
driver.switchTo().frame("foo");
WebElement editable = driver.switchTo().activeElement();
editable.sendKeys("Your text here");
Sometimes this doesn't work, and this is because the iframe
doesn't have any content. On Firefox you can execute the following
before "sendKeys":
((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<br>'");
This is needed because the iframe has no content by default:
there's nothing to send keyboard input to. This method call inserts an
empty tag, which sets everything up nicely.
Remember to switch out of the frame once you're done (as all further
interactions will be with this specific frame):
driver.switchTo().defaultContent();
I found this on http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
Use driver.switchTo().defaultContent(); first then do your operation

ajaxSubmit and Other Code. Can someone help me determine what this code is doing?

I've inherited some code that I need to debug. It isn't working at present. My task is to get it to work. No other requirements have been given to me. No, this isn't homework, this is a maintenance nightmare job.
ASP.Net (Framework 3.5), C#, jQuery 1.4.2. This project makes heavy use of jQuery and AJAX. There is a drop down on a page that, when an item is chosen, is supposed to add that item (it's a user) to an object in the database.
To accomplish this, the previous programmer first, on page load, dynamically loads the entire page through AJAX. To do this, he's got 5 div's, and each one is loaded from a jQuery call to a different full page in the website.
Somehow, the HTML and BODY and all the other stuff is stripped out and the contents of the div are loaded with the content of the aspx page. Which seems incredibly wrong to me since it relies on the browser to magically strip out html, head, body, form tags and merge with the existing html head body form tags.
Also, as the "content" page is returned as a string, the previous programmer has this code running on it before it is appended to the div:
function CleanupResponseText(responseText, uniqueName) {
responseText = responseText.replace("theForm.submit();", "SubmitSubForm(theForm, $(theForm).parent());");
responseText = responseText.replace(new RegExp("theForm", "g"), uniqueName);
responseText = responseText.replace(new RegExp("doPostBack", "g"), "doPostBack" + uniqueName);
return responseText;
}
When the dropdown itself fires it's onchange event, here is the code that gets fired:
function SubmitSubForm(form, container) {
//ShowLoading(container);
$(form).ajaxSubmit( {
url: $(form).attr("action"),
success: function(responseText) {
$(container).html(CleanupResponseText(responseText, form.id));
$("form", container).css("margin-top", "0").css("padding-top", "0");
//HideLoading(container);
}
}
);
}
This blows up in IE, with the message that "Microsoft JScript runtime error: Object doesn't support this property or method" -- which, I think, has to be that $(form).ajaxSubmit method doesn't exist.
What is this code really trying to do? I am so turned around right now that I think my only option is to scrap everything and start over. But I'd rather not do that unless necessary.
Is this code good? Is it working against .Net, and is that why we are having issues?
A google search for
jquery ajax submit
reveals the jQuery Form Plugin. Given that, is that file included on your page where the other code will have access to the method? Does this code work in Firefox and not IE?
Seems like there was too much jQuery fun going on. I completely reworked the entire code block since it was poorly designed in the first place.

asp.net linkbutton client-side problem

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.

Multiple reCAPTCHAs in one ASP.Net page

It is possible to add multiple reCAPTCHAS in one form? I tried doing so, even giving the multiple reCAPTCHAS different IDs, but when I load the page in the browser, only one of them is shown.
Is this by design? I need the two reCAPTCHAS because one is for Login, and the other one is for the Register form, which will be shown on the same page.
Thanks!
WT
Only one Cpatcha is supported in a page at any time. What you can do is use AJAX and lod captcha after the form is loaded.
This might of some help.
After a quick google search, it appears that it's not currently possible. One suggestion I saw was to pop up a modal recaptcha just as the user submits the form. ondemandcaptcha for Ruby.
I was initially lead by this thread to believe there is no simple answer, but after digging through the Recaptcha ajax library I can tell you this isn't true! TLDR, working jsfiddle: http://jsfiddle.net/Vanit/Qu6kn/
It's possible to overwrite the Recaptcha callbacks to do whatever you want with the challenge. You don't even need a proxy div because with the overwrites the DOM code won't execute. Call Recaptcha.reload() whenever you want to trigger the callbacks again.
function doSomething(challenge){
$(':input[name=recaptcha_challenge_field]').val(challenge);
$('img.recaptcha').attr('src', '//www.google.com/recaptcha/api/image?c='+challenge);
}
//Called on Recaptcha.reload()
Recaptcha.finish_reload = function(challenge,b,c){
doSomething(challenge);
}
//Called on page load
Recaptcha.challenge_callback = function(){
doSomething(RecaptchaState.challenge)
}
Recaptcha.create("YOUR_PUBLIC_KEY");
It is now possible to do this easily with explicit recaptcha creation. See my answer here:
How do I show multiple recaptchas on a single page?
It's not too difficult to load each Recaptcha only when needed using the Recaptcha AJAX API, see my post here:
How do I show multiple recaptchas on a single page?
the captcha has an img element #recaptcha_challenge_image element , so after you set the recaptcha in one div say "regCaptch",get that img src attr
,set your other captcha div html to the old one html and then set the #recaptcha_challenge_image src to the src you get , here is a working example
var reCaptcha_src = $('#recaptcha_challenge_image').attr('src');
$('#texo').html($('#regCaptch').html());
$('#recaptcha_challenge_image').attr('src',reCaptcha_src);

Default Form Button in FireFox

I am building a server control that will search our db and return results. The server control is contains an ASP:Panel. I have set the default button on the panel equal to my button id and have set the form default button equal to my button id.
On the Panel:
MyPanel.DefaultButton = SearchButton.ID
On the Control:
Me.Page.Form.DefaultButton = SearchButton.UniqueID
Works fine in IE & Safari I can type a search term and hit the enter key and it searches fine. If I do it in Firefox I get an alert box saying "Object reference not set to an instance of an a object.
Anyone run across this before?
Is SearchButton a LinkButton? If so, the javascript that is written to the browser doesn't work properly.
Here is a good blog post explaining the issue and how to solve it:
Using Panel.DefaultButton property with LinkButton control in ASP.NET
Ends up this resolved my issue:
SearchButton.UseSubmitBehavior = False
I might be wrong and this might not make a difference but have you tried:
Me.Page.Form.DefaultButton = SearchButton.ID
instead of
Me.Page.Form.DefaultButton = SearchButton.UniqueID

Resources