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
Related
Is there a way with ASP.net page (with AJAX) to display some some of busy indicator (just a label is fine) while disabling some buttons (to prevent double-click) and then do the work. At the end of the work, the label changes to indicate the new status.
When I tried to do it this way :
Public Sub BtnEnvoyer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnEnvoyer.Click
BtnEnvoyer.Enabled = False
LblStatus.Visible = True
LblStatus.ForeColor = Drawing.Color.ForestGreen
LblStatus.Text = "Envoi en cours..."
SendEmail()
End Sub
Private Sub EnvoyerCourriel()
' Do some work
LblStatus.Text = "Done!"
BtnEnvoyer.Enabled = True
End Sub
I just see the dn result, nothing in between.
I don't mind using javascript to make it work if needed, or anything else for that matter.
I asked a very similar question a few weeks ago:
ASP.NET Custom Button Control - How to Override OnClientClick But Preserve Existing Behaviour?
The class i created can be dropped onto any form and will prevent double-clicks.
Essentially, i am setting the button to "disabled", but there is nothing stopping you from extending that to call your own client-side code.
You're best bet is to disable the button (like i did), and also show a hidden DIV which contains an animated gif (AJAX loading image).
You might find the discussion on this question helpful:
ASP.Net double-click problem
The solution(s) deal only with the button, but you could extend the idea to disabling more of the DOM and showing a hidden div with your message as part of the client click function.
You should be able to use a bit of jQuery to find the buttons, and disabled them. When I've done this in the past I've also changed the text of the button to "Please Wait...". I wired up the client onclick in conjunction with the postback of the button.
It worked great for me as it stopped the button from being pressed again and also gave the user an immediate visual feedback that they'd successfully clicked the button.
If you need an example I'm sure I can dig out some code for you.
If you want the page to be updated before the postback result comes back, you'll have to use javascript, something like this. This is a general approach, that you should probably customize to what you need.
In your html:
<head>
<script type="text/javascript">
function ShowWait() {
document.getElementById('labelspan').innerText = 'Loading...';
}
</script>
</head>
In the page setup:
BtnEnvoyer.OnClientClick = "ShowWait();";
Then when the button is clicked, ShowWait will apply whatever visual effects you want while the postback is actually processing. As soon as it's ready, the whole page will be replaced with the results of the postback.
I am using modalpopup to enter some value in a textfield. After the value is selected in the modalpopup view, the modalpopup is closed and the value takes the appropriate value. Even if the value is displayed in the textfield, the textfield1.text returns an empty string. When I see the source code (html), I see that even the textfield isn't displaying anything; it hasn't really had this value input, because the appropriate html input field hasn't got a value yet.
This is the code I use to fill this textfield:
function CloseRequestModal(s)
{
document.getElementById('<%=txtRequest.ClientID%>').value = s;
var mpu = $find('<%=ModalPopupExtender3.ClientID%>');
mpu.hide();
}
Please help.
I would need to see source HTML cause it looks like you have template language mixed into your javascript but perhaps instead of "textfield1.text" you use "textfield1.value"?
Additionally, you would need to view "generated" source (with a browser plugin) or inspect the node with web inspector on safari/chrome or firebug on firefox in order to see the change that you made with javascript.
i fixed this problem in an alternate way.
even if the value is there (in the textfield), none of the events is fired, to let know the browser / compilator that the value really exists.
so i decided, despite editing the value of the textfield, i store this value in the session too. in this case, the value is displayed for user needed in the interface, and on the other hand i use the value that i stored in the session.
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.
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;
I'm using the AutoComplete control from the ASP.NET AJAX Control Toolkit and I'm experiencing an issue where the AutoComplete does not populate when I set the focus to the assigned textbox.
I've tried setting the focus in the Page_Load, Page_PreRender, and Page_Init events and the focus is set properly but the AutoComplete does not work. If I don't set the focus, everything works fine but I'd like to set it so the users don't have that extra click.
Is there a special place I need to set the focus or something else I need to do to make this work? Thanks.
We had exactly the same problem. What we had to do is write a script at the bottom of the page that quickly blurs then refocuses to the textbox. You can have a look at the (terribly hacky) solution here: http://www.drive.com.au
The textbox id is MainSearchBox_SearchTextBox. Have a look at about line 586 & you can see where I'm wiring up all the events (I'm actually using prototype for this bit.
Basically on the focus event of the textbox I set a global var called textBoxHasFocus to true and on the blur event I set it to false. The on the load event of the page I call this script:
if (textBoxHasFocus) {
$get("MainSearchBox_SearchTextBox").blur();
$get("MainSearchBox_SearchTextBox").focus();
}
This resets the textbox. It's really dodgy, but it's the only solution I could find
this is waste , its simple
this is what you need to do
controlId.focus(); in C#
controlID.focus() in VB
place this in page load or button_click section
eg. panel1.focus(); if panel1 has model popup extender attached to it, then we put this code in page load section
How are you setting focus? I haven't tried the specific scenario you've suggested, but here's how I set focus to my controls:
Public Sub SetFocus(ByVal ctrl As Control)
Dim sb As New System.Text.StringBuilder
Dim p As Control
p = ctrl.Parent
While (Not (p.GetType() Is GetType(System.Web.UI.HtmlControls.HtmlForm)))
p = p.Parent
End While
With sb
.Append("<script language='JavaScript'>")
.Append("function SetFocus()")
.Append("{")
.Append("document.")
.Append(p.ClientID)
.Append("['")
.Append(ctrl.UniqueID)
.Append("'].focus();")
.Append("}")
.Append("window.onload = SetFocus;")
.Append("")
.Append("</script")
.Append(">")
End With
ctrl.Page.RegisterClientScriptBlock("SetFocus", sb.ToString())
End Sub
So, I'm not sure what method you're using, but if it's different than mine, give that a shot and see if you still have a problem or not.
What I normally do is register a clientside script to run the below setFocusTimeout method from my codebehind method. When this runs, it waits some small amount of time and then calls the method that actually sets focus (setFocus). It's terribly hackish, but it seems you have to go a route like this to stop AJAX from stealing your focus.
function setFocusTimeout(controlID) {
focusControlID = controlID;
setTimeout("setFocus(focusControlID)", 100);
}
function setFocus() {
document.getElementById(focusControlID).focus();
}
I found the answers from Glenn Slaven and from Kris/Alex to get me closer to a solution to my particular problem with setting focus on an ASP.NET TextBox control that had an AutoCompleteExtender attached. The document.getElementById(focusControlID).focus() kept throwing a javascript error that implied document.getElementById was returning a null object. The focusControlID variable was returning the correct runtime ClientID value for the TextBox control. But for whatever reason, the document.getElementById function didn't like it.
My solution was to throw jQuery into the mix, as I was already using it to paint the background of any control that had focus, plus forcing the Enter key to tab through the form instead of firing a postback.
My setFocus function ended up looking like this:
function setFocus(focusControlID) {
$('#' + focusControlID).blur();
$('#' + focusControlID).focus();
}
This got rid of the javascript runtime error, put focus on the desired TextBox control, and placed the cursor within the control as well. Without first blurring then focusing, the control would be highlighted as if it had focus, but the cursor would not be sitting in the control yet. The user would still have to click inside the control to begin editing, which would be an UX annoyance.
I also had to increase the timeout from 100 to 300. Your mileage my vary...
I agree with everyone that this is a hack. But from the end-user's perspective, they don't see this code. The hack for them is if they have to manually click inside the control instead of just being automatically placed inside the control already and typing the first few letters to trigger the auto lookup functionality. So, hats off to all who provided their hacks.
I hope this is helpful to someone else.