How do I remove fields from a web form using ASP? - asp.net

I have a web page that has a web form for signing up. I want to remove fields. I've tried removing the field code from the .asp file but obviously there are other things that I need to remove along those lines. I have full access to all the code but I need help knowing where things are linked as far as making the form work again. Our programmer bailed.
A step by step guide would be great on this. thanks.

If they're just .ASP files, you should be fine removing the field tag, along with any references to it.
I.e. you'd delete this line:
<asp:TextBox id="text1" runat="server" />
and do a search for the 'id' attribute in the rest of the file (a find on 'text1' in this case), and remove those lines.

If everything to do with that for in in the same ASP page, it's easy. You can do a simple text search for the names and/or IDs of each form field. Sometimes they're referenced in a javascript block, so you'll have to comment-out some of the form validation code referencing those fields.
If they've used some dumb Dreamweaver script for all this - good luck!
If there are #include statements, or references to external JavaScript files it's more work - you'll have to trace through them as well, hoping they don't have their own included files as well.

After removing the input parts of the markup, if it is a .asp (assuming asp v3 instead of asp.net) it is also worth going through the <% %> tags part of the page to look for references to the removed inputs. If it's asp.net then check the vb.net / c# code in the script runat server block in the page, or look in the code behind file for references and recompile.

Related

Checkboxes in ASP.NET

I am trying to use a checkbox that is dynamically declared in an .vb file that I am trying to write into my .aspx page. I am able to write a normal checkbox of <input type='checkbox /> from the .vb Class using Response.write, but it comes up blank when using <asp:Checkbox runat='server' />I need to pass whether or not the box is checked back to the server, because I am having to either approve something if one is checked, reject something if the other is checked or do nothing if neither are checked. I have figured out how to make them mutually exclusive either way so that is not the problem. Does anyone have any recommendations?
Your problem lies in the order that the pages are compiled in: When you place an asp control like the asp:checkbox, it is compiled into a regular checkbox with some javascript attached when it is sent over to the client.
When you write the string "<input type='checkbox />" to the page from the code-behind it is writing that string directly to the page, after the aspx page has compiled its controls, but since that is valid html the browser renders the control. When you write the asp:checkbox, the browser doesn't know what to do with it, because it is not valid html. In addition, the page has already been compiled, so there is no chance of .net creating the correct control for you.
You need to programmatic add the control to the webpage by creating a new control through the code behind
This site does a great job explaining it
And #toodles seems spot on. Writing static html and asp.net are two totally different ball games. I would spend a bit of time (like hours/days) reading/watching learning material to help you get on your feet.
The technical answers you are getting are all good. However, your question indicates that you really need to start by learning how asp.net server controls work. I suggest spending a couple hours watching the videos at http://asp.net and particularly http://www.asp.net/general/videos/intro-to-aspnet-controls
Then focus on understanding the page lifecycle and you'll have enough of the basics to be much more effective at asp.net. Have fun!
You can't use response.write to create server controls.
See this site for an example of the right way to do it:
http://msdn.microsoft.com/en-us/library/kyt0fzt1.aspx

localization of big project

I need to localize an asp.net webapp with lots of pages.
So far what i'm doing is replace all text with literals where needed and i'm adding <%$ Resources: restype, reskey %> tags wherever needed. All the strings come from my database.
The problem is putting all the text in the database it's just a huge time spender.
I really don't want to be putting all the text in the database manually because everytime i finish a new page i have to go over the same excercise again.
So i came up with an idea:
What if i extended the localization resource handler with a default value like this (pseude code):
<asp:literal runat="server" Text='<%$ Resources: restype, reskey, 'This was the hard coded text' %>' />
When the page was first loaded the string resource wouldnt be in the database, but having the default text i can add it with the known resource type and key to my database. I could prefix the default values with a question mark for example. This allows me to check my table with strings and everywhere i see a text with a question mark i know it needs translating.
This way i only have to add resource tags to my markup and i avoid inserting all the text in my database. I just have to make sure to load every page once, which i can do locally in debug and then send the non-translated labels to a translator.
Please advise on this approach.
What we do here where I work is to declare string resources using special helper class. When the application is run, new string resources defined in code are auto-inserted into the database with their default value. The application works without any preparation steps. Later you can change the strings.
But yes, it requires some wrapper code to write.
Sounds like a nice idea, especially if you can't go along with the standard resource files mechanism which is automatically generated by VS.
Rick Strahl has written a solution for localizing ASP.net webapps to the DB. He's written some kind of Ajax UI which would even allow your users to translate the Webapp. The source code is also open, so you may take a look at it when developing your own solution.
Here's the link: http://www.west-wind.com/WestWindWebToolkit/

Linking to ascx file

I am utilizing controls in my asp.net application. I have a register tag the source of which needs to be dynamic. I am using the line below which functions correctly when the full path is specified but when I change it to the variable I get a parser error. Any idea how I can go about doing this?
Thanks
It might be better to use Load Control from the code behind of the aspx page.
If I'm understanding you correctly — you can't use a variable in those directives (Page, Register, etc). They have to be constant expressions.
However, it is possible to dynamically load ASCX controls. You would have to do this in code, though, and it would not involve the Register tag.

How to create regions in an aspx file?

I wonder is there any way we can create regions in aspx page as we create it in our cs pages.
not as Expandable, but in HTML it is normal to use the comments in order to create blocks of code
<!-- Start: Login access form -->
... Code ...
<!-- End: Login access form -->
Unfortunately no (at least not in Visual Studio).
You can select the commented section, then right click, collapse tag.
I don't think there's a way to do this.
However, I would suggest that if you are feeling the need to do this because your .aspx pages are very large, you might should look at redesigning it, or breaking it apart into User Controls (.ascx) or figure out a more effective use of master pages.
Not sure if that's the reason behind your question, but if it is, it's just a thought to pass on.
If you're using Visual Studio (could be the web essentials plugin, I can't remember if its native), the following snippet will be expandable in HTML files (including CSHTML). Unfortunately, these are not expandable in ASPX or ASCX files.
<!--#region Example -->
...code...
<!--#endregion Example -->
In an ASPX or ASCX file, perhaps you'd rather want to go with this:
<%-- START Example --%>
...code...
<%-- END Example --%>
They're still not expandable, but those will not get rendered out and therefore not be visible when right clicking on the page and viewing Source Code. You'll only see them in the development file.
P.S.
I didn't realize how old this question was until I finished typing out my answer. So I'm just going to go ahead and put this here anyway since it looks like it could use an update.
Visual Studio does a pretty good job of identifying elements with a significant amount of content to make it collapsable dynamically but thats the closest you going to get.
It might occur to you to place a series of element sibling in a DIV so that the div can be collapsed in visual studio. Thats very tempting but I would advise against it.
Regions are an IDE convenience that allow you to name a segment of code that may span multiple functions or procedures and be able to collapse/expand the whole segment as a whole. Visual Studio provides this feature only for code and not for HTML/ASPX/CSS portions of a file. For instance, you can create Regions within the <script runat="server"> section of an ASPX file.
You could use a div and put everything inside it

Multiple localized aspx layouts

I want to localize an application, and currently use the App_LocalResource resx files for language changes. However, I want to change the layout of the controls on an ASPX page dependant on locale. I know it is possible to set visible from the resx file.
For example; my default (en-US) could have
"firstname" : [textbox]
"surname" : [textbox]
where as de-DE I would want to swop the order
"surname" : [textbox]
"firstname" : [textbox]
The aspx pages will use the same CodeBehind.
I guess what Im looking for is something along the lines of having;
default.aspx
default.de-DE.aspx
default.aspx.cs
Where the default.de-DE.aspx contains all the same controls etc as default.aspx and even has the same directive;
<%# Page CodeFile="Default.aspx.cs" Inherits="MyNamespace.Default" %>
Then the .NET framework picks up this one rather than default.aspx layout..
I have worked for quite some time on a project that does essentially what you are looking to do; We split it by folder is the only difference, so /en-US/Default.aspx and /de-DE/Default.aspx. The pages share a common code-behind for functionality. It works pretty well, with a few gotchas:
Making sure the files are always updated together - This is necessary because of the shared code behind. If you update the code behind, all the referenced controls had better exist on the pages.
Be careful about your control references - we've run into some issues where controls were referenced from the wrong folder, resulting in some interesting (and sometimes hard to diagnose) issues.
Personally I would recommend splitting it into folders instead of using the file naming structure because it also very easily allows you to provide locale specific images and CSS . Also it allows you to override the common behavior of a page by just adding the appropriate code behind (you could do this too, but then your class names will be strange due to the periods in the file names[eg. ApplicationNS.Default_de_de as opposed to ApplicationNS.en_us.Default]).
In a similar situation I've created a custom server control with a localizable "RenderOrder" property. It also exposes Surname and FirstName as properties.
A similar scenario sometimes is required for detailed address fields too.
I would say the best way to handle this would be via CSS.
You can easily apply a different stylesheet, which can completely change the layout of your website, and thereby move all the controls around. This solution also allows you to easily do alternate renderings for mobile browsers, or printing, or any other reason and is very versatile.
As other s stated, you will obviously have other localization issuse such as translation or date/currency formats as well. But you will have to solve those via other means.
Here are some examples of the same website, with 100% the same HTML, where only the CSS has changed, rendering completely differently.
http://www.csszengarden.com/?cssfile=/212/212.css&page=0
http://www.csszengarden.com/?cssfile=/211/211.css&page=0
Assuming your simple case where you have just two controls that you want to flip :
<div>
<div class=class1>Control1</div>
<div class=class2>Control2</div>
</div>
Then based on the location, in your stylesheet use either floats, or absolute positioning (within the parent container) to reposition the two divs. 100% identical html, with two different layouts?
ASPX
<link rel="stylesheet" id="Stylesheet1" type="text/css" runat="server" />
ASPX.cs
Stylesheet1.Attributes("href") = ResolveUrl("~\styles\StyleSheet.css")
I should vote for building a control that's the way you display dates and times which is heavily dependent on localization
Resources and Localization in ASP.NET 2.0
Custom ASP.NET Server Controls and Language Localization
Good general article on localization

Resources