works on localhost but not on webserver

Posted on 2013-12-23
Last Modified: 2014-01-02
I am trying to make the Enter key work during login for my app at by setting up a default button in a panel.  The code works in localhost mode, but on the web server gives the often seen error about needing the default button to be of type IButtonControl. What am I doing wrong?

My best guess is that the button is not properly identified in the code behind.

Protected Sub Login1_PreRender(sender As Object, e As EventArgs)
        Dim btnLoginDefault As Button = TryCast(Login1.FindControl("LoginButton"), Button)
        pnlLogin.DefaultButton = btnLoginDefault.UniqueID
    End Sub

Open in new window

Question by:Mark Klein
  • 5
  • 2
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39736948
This is what I get from your web server:

Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

Are those the same as you have on your computer at 'localhost'?

Author Comment

by:Mark Klein
ID: 39736978
that's the AspNet version. My default browser in Chrome, not MS.  Where do I find the IIS version?
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39736990
Browser doesn't matter because ASP.NET is run on the server.  IIS versions are tied to the Operating System.  See here:
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Author Comment

by:Mark Klein
ID: 39737860
I eventually realized that. I'm using Win7 in a dual boot setup on a Mac with Parallels, so IIS at 7.5 is probably OK.

Been doing this for a while w/o this problem.  I'm a relative newbie, a geezer back to programming after (literally) 50 years, so there is a lot I don't know. I built the app you see for my son, now doing defensive programming trying to handle users who press Enter instead of the button they should.

I suspect the problem is related to the button identifier, which changes during compilation. I am trying to make the button on the screen the defaultbutton in a panel.  I've seen several posts about this situation being "squirrely" in VWD, and some need to modify the UniqueID that I append to the the button ID.

Author Comment

by:Mark Klein
ID: 39739083
My code, shown below, is unable to find the button that I want assigned as the defaultbutton. Hence the Enter key is directed elsewhere, which is probably while it's failing.  From reading around the net, it seems that because this login page is coupled to a master page, that master page is causing the problem.

Protected Sub Login1_Load(sender As Object, e As System.EventArgs) Handles Login1.Load
        MyBase.LogActivity("Visiting the Login page.")
        Dim btnLoginDefault As Button = TryCast(FindControl("Login1$LoginButton"), Button)
        pnlLogin.DefaultButton = btnLoginDefault.UniqueID
    End Sub

Open in new window

I've set a breakpoint on the Dim line, and the breakpoint is reached. The code goes through here and fails here

Accepted Solution

Mark Klein earned 0 total points
ID: 39743681
I "solved" the problem by not using the panel defaultbutton.  Inside the Load event for the page I put

  Dim FirstTextBox As TextBox = TryCast(Login1.FindControl("username"), TextBox)
        Page.Form.DefaultFocus = FirstTextBox.ClientID
        Dim btnLoginDefault As Button = TryCast(Login1.FindControl("LoginButton"), Button)
        Page.Form.DefaultButton = btnLoginDefault.UniqueID

Open in new window

I was led to this approach by

Why the code based on the panel default button doesn't work, or why visual web developer led me astray by having my code work in localhost but not on web server, I still don't know

Author Closing Comment

by:Mark Klein
ID: 39750942
Had to solve this myself.  Still don't know why my original code only worked in localhost.

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
Open a word document 23 33
Excel import error " External table is not in expected format" 12 48
Help with solving error related to resources file 4 36
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Internet Business Fax to Email Made Easy - With  eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now