Setting focus on textbox causes CSS overflow - c#

I have a textbox that I set the focus to depending on some operations by the user. After do so the CSS for the page is thrown off; page shifts to the left. Below is the CSS involved:
width: 960px;
overflow:hidden;
margin-top: 20px;
background: transparent url(../images/pattern.png) repeat;
Any clues as to what is happening and how I could resolve this issue?

I have to do more investigation into why, but the following resolved my issue. Adding a meta tag http-equiv="X-UA-Compatible".
There was a similar issue discussed here as well
http://forums.asp.net/t/1485816.aspx?Scriptmanager+SetFocus+set+s+focus+but+I+can+t+type
Hope this helps anyone running into this issue. Additionally, the using the meta tag works no matter if you are utilizing the ScriptManager's SetFocus method or the Page/Control focus method.

Related

Adding a Textbox destroys Menu-Layout

I'm working on a little project with ASP and C#.
In my project I'm using a masterpage for the navigationbar on the top of my pages, looking like that:
The navigationbar contains some normal navigation-points and one to log out with float: right;
On all of my diffenrent pages this works excepted for one.
The only difference is, that on this special page I have some textbox-elements like this:
<asp:TextBox ID="tbTOP1sum" runat="server"></asp:TextBox>
As soon as I only enter one of this textboxes my navigationbar looks like that:
It doesn't matter what sort of element im adding, everything is okay, excepted with this textboxes.
I noticed that this only happens in Google-chrome, not with Firefox and not with Internet-Explorer or Edge. Another thing i found out is, that disabling and enabling the CSS-rule in Chrome-Page-Inspector fixes the problem.
I have no idea what to do...
Thanks in advance for your help!
I have the same issue sometimes. When you change it in the inspector go into your code and make the same change and save/build, go to the web browser and do a hard refresh with "ctrl+F5". If it still does not work, wrap your logout a link in a div and then call it in CSS. Set the position to relative, and then put the top: -55px;
It finally turned out, that adding display: inline; to the of the navigationbars <ul> is all to do.
Another way is to do it with table columns. One for the normal content and one for the logout.
Thanks for the other answers!

ASP.NET buttons became shorter

I haven't changed anything in .css file, but every button in my project (in masterpage and .aspx files became shorter (~25px length)). I remember that i had something like this long time ago, but can't remember the solution. Could anyone tell me what's the cause of it and how to fix it? Thanks
Use Developer Tools on IE or Firebug on Firefox (hit F12) and trace the css.
Here is an example of how you can do that:
Whatever the problem is you can change the length of buttons by marking them as "!important" this will apply the new CSS to all the buttons and whatsoever length is applied earlier will get diminished.
for e.g.:
.example { font-size: 14px !important; }
Accept the answer if it helps you

Can't change position of buttons in C# ASP.net

I use VS 2010 . I add button to webfrom that created, but I can't change his position.
I read in previous questions that I need to change the layout to absolute , but it didn't work. when I drag the button to the center it's back automatically to left-center..
you can see that in the picture:
how can I fix that?
Thank you!!
solution:
Tools -> Options, and set HTML Designer -> CSS Styling to "Change positioning to absolute.."
Changing the position to absolute seems more like a workaround which would introduce further problems after "solving" this one. Unless you really know what you're doing for styling, don't do that.
Centering an element on a webpage is really a matter for the CSS styling. Take a look at the markup (HTML) view and find where that button is. You can add a class to that button for the CSS styling:
<asp:Button runat="server" ID="Button1" CssClass="centeredButton" ...
Then in your site's CSS file (Site.css might be the standard in the ASP.NET template? I don't remember) you can apply the styling you're looking for. There's a lot you can do at that point. Not knowing how the rest of the page is laid out, I can only offer very random suggestions. Something like this for example:
.centeredButton {
display: block;
margin: auto;
}
That's one way to center that particular element. There are definitely more, depending on how the rest of the markup/layout is structured.
First of all i recommend not to use this drag options. Because what happens behind this whenever you drag a button or anything, will make you more confused. You can do it using div or table.

Reasons Why Custom Validator May Not Be Showing Error Msg?

Unfortunately I can't show you the code so I am just going to have to explain the problem.
I have a detail view that is in a update panel. I added a custom validator that should appear open the condition if Radio Button A is selected TextBox A must have a value in it.
I setup an OnServerValidate method that checked for this and if it fails then I set args.Valid to false.
However my error message never appears. If I look through IE Developer Tool I see my customer validator with the hard coded message but it is hidden(visibility: hidden).
I tried to find the customvalidator and force visibility to show and even went as far to try to remove it through customValidator.Style.Remove("visibility") yet nothing works. The message is always hidden.
The page does fail validation as if that condition is met my page won't save. It just won't show my message that I set in custom validator.
Edit
I also tried doing Visible="true" in the aspx code of the custom validator and it stil will not show the error msg and in developer toolkit shows it as hidden.
Same problem here. I tried everything, changing the style attribute on the validator, using Javascript to change the style, Jquery, etc. Nothing would work, its style was always "visibility:hidden".
Eventually I ended up doing the most ridiculous workaround by just adding a label with my error message:
<asp:Label ID="ErrorLabel" runat="server" Visible="False" CssClass="validator-red">
Error message here
</asp:Label>
and manually displaying it in the validation event handler:
protected void Validator_ServerValidate(object source, ServerValidateEventArgs args) {
// Validation code, set args.IsValid here.
ErrorLabel.Visible = !args.IsValid;
}
That's functionality that's meant to be included with all validators, but it looks like MS stuffed it up on this one. At least this works reliably. Also don't forget to set Display="None" on the validator as you won't be needing that.
I ran into a similar problem myself and found this thread, just before I found an answer...not sure if it's still worthwhile, but here's what I did.
1) I added the following (VB.net code, but you should be able to port it to C#):
My_Custom_Validator.Attributes.Add("class", "invalid")
2) I created a CSS invalid class rule:
.invalid {display: block !important; visibility: visible !important;}
The !important will override the inline CSS created by the .NET code. Setting it on display: block; isn't necessary, but I put it just in case.
This doesn't answer your question as to why the visibility: hidden; inline CSS appears...it's just a workaround.

Obtaining Background-image from stylesheet using C#

I am trying to get the value of a "Background-image"-tag in a stylesheet which is used on my web-site. The style-sheets are referenced from the HTML file as follows:
<style media="all" type="text/css">
#import "master.css";
</style>
<style media="all" type="text/css">
#import "layout.css";
</style>
The layout.css file contains:
#frontpage-main-features {
background: url('../elms/frontpage-main-gradient.jpg') no-repeat left top;
margin-bottom: 10px;
}
#frontpage-main-features-inner {
width: 700px;
padding: 20px 20px 10px 20px;
background: url('../elms/frontpage-main-gradient-bottom.jpg') no-repeat left bottom;
}
In the master.css file a background image is referenced which is then overloaded in the layout.css file by the #frontpage-main-features-inner section. I would very much like to access the "background"-tag in order to see which background image is currently being shown in a specific part of the page. Any suggestions?
Best,
Michael
Why not just use FireBug / the IE8 dev console? load the page, open the console, find the piece of html you are looking for and inspect the css properties, it will give you all applied styles for that element, overridden properties will be striked through...
You're talking about looking at the markup of the page from C#, i.e. this is the markup that is not an ASP.Net server control and is not viewable by ASP.Net.
Sorry, that's not possible using ASP.Net. You can only view data that is marked for server to view.
Why do you need this? There could be another way to do whatever you are trying to do. Maybe you need to turn the problem around (get markup to get the class name from c#) which is easier.
The problem is that CSS rules are not applied or enforced on the server, they are applied by the client browser. You could perhaps create a parser that goes through the referenced CSS files and figures out what image should be displayed but you really can't know with certainty how the client browser will interpret and apply the CSS rules.

Categories

Resources