I'm an ASP.NET web part novice. I've built a few simple ones using only a class that derived from WebPart and overriding the CreateChildControls method, but nothing really very substantial. My question is whether it's possible to have a web part that also takes advantage of a separate html/asp.net markup file that will help provide some structure to the web part's output. In the past I just created server controls and added them to the controls collection, but this seems like a silly way to try to create a non-trivial layout. Can I do this? Do I have to use an ascx user control or can I bypass that step? There are a lot of hello world tutorials on web parts out there, but none seem to go past the CreateChildControls override. Thanks!
Monday, March 7, 2011
Whats the best way to resolve name conflicts in javascript?
I recently wrote some javascript code that filled a drop down list based on some XML, pretty simple stuff. The problem was I had to write similar code to do almost the same thing on a different page.
Because the code was almost identical I named most of the functions the same, thinking that they would never be included in the same page. However, naming conflicts arose because both javascript files were eventually included in the same HTML page.
When I had to go back and change the names I simply added first_ or second_ to the method's names. This was a pain and it doesn't seem very elegant to me. I was wondering if there is a better way to resolve name conflicts in javascript?
-
Going slightly object oriented and using namespaces should prevent such conflicts IMHO. I'm not much of a web developer, so there might be better ways to do it specifically for Javascript, but this is generally what's done.
-
Try the JavaScript module pattern (or namespaces) used in various libraries.
Try to be DRY (don't repeat yourself) so you can avoid name collisions. If the code is almost the same you better avoid code duplication by creating a function which can handle both cases. The function can take two parameters: which dropdown to populate and with what data. This helps maintainability as well.
update: I assume that you take the XML from an AJAX request. In this case you can create on-the-fly anonymous functions with the appropriate parameters for callback inside a loop.
-
I would look at how I could merge the two pieces of code (functions?) into a single function. If you need to populate a list box, then pass the list box id into the function, so you are not hard-coded to operate on one single control only...
I did this on my rocket business's web site where I sold rocket motors with different delay values, but in essence, they were the same product, just a different delay value.
Perhaps this might try and explain what I'm trying to say... I use this if an image file happens to be missing, it will display a "no image" image in place of the real image.
function goBlank(image) { if(image) { var imgobj = document[image]; imgobj.src="/images/blank.gif"; } }In this case, you call it with:
<img src="/images/aerotech.gif" name="header" onError="goBlank('header');">If you need more example with things like list boxes used, let me know. Perhaps even post some sample code of yours.
-
Another option (if possible) is to carefully tie the code to the element itself.
e.g.
<input type="text" name="foo" id="foo" value="World" onchange="this.stuff('Hello ' + this.value);"/> <script> document.getElementById('foo').stuff = function(msg){ //do whatever you want here... alert('You passed me: ' + msg); }; </script>LarryF : I like that. Kinda tricky, but I can see some uses for that...
Did isset work differently in older versions
Hey!
I got some legacy code that has this:
<?PHP
if(isset($_GET['pagina'])=="homepage") {
?>
HtmlCode1
<?php
} else {
?>
HtmlCode2
<?php
}
?>
I don't know exactly why but this seems to be working. The htmlcode1 is loaded when I have ?pagina=homepage and the htmlcode2 is loaded when the pagina var doesn't exist or is something else (haven't really seen with something else, just not there). The website is using php4 (don't know the exact version). But really, how can this work? I looked at the manual and it says isset returns a bool..
Anyone?
-
isset()returns true or false. In a boolean comparison,"homepage"would evaluate totrue. So essentially you got here:if ( isset($_GET['pagina']) == true )If pagina equals anything, you will see HtmlCode1. If it is no set, you will see HtmlCode2.
I just tried it to confirm this, and going to
?pagina=somethingelsedoes not show HtmlCode2. -
I suspect that it's a bug as it doesn't really make sense to compare true/false with "homepage". I would expect the code should actually be:
if (isset($_GET['pagina']) && ($_GET['pagina'] == "homepage")) { } -
Some ideas how this could work (apart from the previously mentioned "homepage"==true):
- Isset has been redefined somewhere?
- It's a self-modified version of PHP?
-
The problem is that "==" isn't a type-sensitive comparison. Any (non-empty) string is "equal" to boolean true, but not identical to it (for that you need to use the "===" operator).
A quick example, why you're seeing this behavior:
http://codepad.org/aNh1ahu8And for more details about it from the documentation, see:
http://php.net/manual/en/language.operators.comparison.php
http://ca3.php.net/manual/en/types.comparisons.php (the "Loose comparisons with ==" table specifically)AntonioCS : Thanks! This must be why it is working
Developing apps for the nokia n73 in Java?
Hello,
I'm trying to find out if it's possible to develop a key capturing application to analyse writing styles when using the SMS composer for the n73 using S60 2nd Edition, Feature Pack 3 SDK in Java? Originally, I thought that all Java applications would be sand-boxed making it difficult to call the native key capture functions available to symbian, but nobody has been able to clarify this for me. Does it hold any truth?
Thanks,
A
-
Note: This answer comes from my friend who knows a lot more about these things.
As this J2ME FAQ states,
Can I access the phone's j2me? (memory, phone book, inbox, pictures...) ?
Generally no, this is considered a security risk and most manufacturers don't allow it. However, a very small minority do, so check out their developer's site.So that'd be no. There's no direct way in MIDP libraries to access that data anyway. It may however be possible if you're lucky, but don't count on it. Also according to Sun this may be possible in MIDP3.
-
I'll be talking as a user: Opera Mini (a java-based application) is able to read and write user data (phone memory and memory card).
And I've also seen java-based applications that access hardware such as the phone's camera, and seen apps that call system APIs such as vibration or sound notifications.
However, I don't know how they implemented those things.
Note1: Nokia N73 is based on S60 3rd edition not 2nd edition.
Note2: In some cases (such as accessing user data), user authorization is required, unless the application is signed using a certificate.
-
I've just started hacking about with my Nokia 6300 and J2ME. This phone supports MIDP2 and J2ME, but unlike the N73 - it's Series 40, and doesn't use symbian for it's operating system.
One of the applications that I want to write, needs to make use of the phone book and as far as I'm aware this is possible using the PIM API (JSR-75).
AFAIK you can actually access SMS messages using C++ under Symbian. Try this link
Testing C code using the web
I have a number of C functions which implement mathematical formulae. To-date these have been tested for mathematical "soundness" by passing parameters through command line applications or compiling DLL's for applications like Excel. Is there an easy way of doing this testing over the web?
Ideally something along the lines of:
- compile a library
- spend five minutes defining a web form which calls this code
- testers can view the webpage, input parameters and review the output
A simple example of a calculation could be to calculate the "accrued interest" of a bond:
Inputs: current date, maturity date, coupon payment frequency (integer), coupon amount (double)
Outputs: the accrued interest (double)
-
The quickest thing I can think of is to have these C programs compiled on the server. And create a PHP page that received command-line parameters and then execute compiled program on the server, parsing the output. Technologies other than PHP would also work just fine. What you need to figure out, for specific technology, are:
- How to start a process
- How to redirect standard input/output
I have also seen number of web site which let users submit their C code and then it get compiled on the server. After that the program will be given some input file and give output. The output of program is then verified with correct answer. For example visit this site, http://acm.timus.ru/
-
You should have a look into automated testing. Manual tests will all have to be repeated every time you change something in your code. Automated tests are the solution for your kind of tests. Let testers write test cases with the accompanying results, then make them into unit tests.
See also: unit testing
Avi : True, but this doesn't answer the question.Norman Ramsey : Sometimes a person just asks the wrong question. -
Or similarly, create a Perl CGI that checks input values and then passes them through to the C program. BTW This should only be done for testing and not for final deployment.
You should really automate the testing to check your behaviour is as expected over a wide range of values.
Or shouldn't you be testing this in an environment that is as close as possible to the final deployment environment?
cheers,
Rob
-
This is what you're looking for:
It will execute C, C++, D, Haskell, Lua, and many others online, and display the results.
If you've got a large library to compile it may get unwieldy, but testing a function briefly is simply a matter of pasting the code and hitting "Submit".
-
If you're going to do this, you should be sure that every web interaction is captured in a permanent database of tests. Then you can use this database to
Automatically re-run all tests if the software changes
Possibly find inconsistencies that result if a person gives you the wrong answer
In other words, the web form should be the front end to a persistent infrastructure for testing, not a means of running tests that disappear just after they are viewed.
-
This sounds much like FIT. You could probably make a new fixture for it, or for one of the other language ports like the Python one, that calls a C library with your function. This would take advantage of the work that's gone into making FIT convenient, the kind of work Norman Ramsey recommends in his answer.
Dynamically creating a project in VS2005 using C#
Is it possible to progmatically or dynamically create a project in VS2005 using c#? If so could someone provide some ideas or links on how to accomplish this?
-
Visual Studio Projects are "simply" XML files. I say simply because there is a lot going on in them. To get an idea of what they consist of: Create an empty project and open up the csproj(C#.NET project) or vsproj (VB.NET project) in a text editor.
You could then generate this XML file in via code.
-
.csproj files are actually XML documents that represent msbuild executions.
The files can be generated using System.xml, and if you need to validate it there's a schema detailed here.
-
You can also create and edit msbuild files programatically using the msbuild api. See here for details: http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.project.aspx
Here's an example that creates a project that compiles a single .cs file and references an external assembly:
Engine engine=new Engine(); engine.BinPath=RuntimeEnvironment.GetRuntimeDirectory(); Project project=engine.CreateNewProject(); project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets", null); BuildPropertyGroup props=project.AddNewPropertyGroup(false); props.AddNewProperty("AssemblyName", "myassembly"); props.AddNewProperty("OutputType", "Library"); BuildItemGroup items=project.AddNewItemGroup(); items.AddNewItem("Reference", "Some.Assmebly"); items.AddNewItem("Compile", "somefile.cs"); project.Save("myproject.csproj") -
If your wanting to be able to create the same things over and over again, Visual Studio supports templates. It even has macros that expand when a file is created from the template. For instance, $username$ would be replaced by the name of the logged in user when a file based on the template was created.
If that's not what you're trying to do, then you might be about to use the Visual Studio extensibility to control the creating of projects.
-
Take a look at the source code of this CodePlex project: STSDev
It ends up being a WinForm app that dynamically produces a Visual Studio Solution with a Project.
It is geared for Sharepoint, but the idea it uses is what you are looking for.
Keith
-
Visual Studio project templates can be created which allow child projects to be created within them. This wont be truely dynamic as you define what child project templates to run during the project creation.
To be truely dynamic you need to do either of the following:
- Programatically create the csproj/ vbproj file along with all items you want in there. This would include setting references, etc in the XML
Or:
- Create a project template and hock in through the VS project creation mechanisums to call the create project method. This can be very tricky as I found 0 documentation on it and was learning how to do it by reverse engineering from the MS ASP.NET MVC project create wizard DLL (as that will dynaically create a Unit Test project)
-
Hi
have a look at Codus, the 1.3.2 the source code is downloadable
It creates business objects from the DB, it does it by opening Visual Studio and adding in the files, you can see it happen. (creates the project and files)
HTH
bones
Change an image to text via CSS for printing?
Lets say I have a header banner on a webpage I'm about to print. Instead of wasting someone's ink printing the entire block of the image, is there a way via css to replace the image with text of H1 size?
-
You could put an
h1element and an image in the same place in the source, and have the image CSSdisplay:nonefor print media, and have theh1set todisplay:nonefor screen media. -
Bryan, typically on things like logos I use image replacement for the graphic anyway so the logo itself is really in an H1 tag. Then in my print style sheet. I do something like this...
h1#logo a, h1#home-logo{ text-indent: 0 !important; background-image: none !important; font-size: 1.2em !important; display: block !important; height: 1em !important; width: 100% !important; text-decoration: none !important; color: black !important; }Which removes the image replacement and shows the text. Make sure of course that you call this stylesheet separately using
media="print". -
I usually just add the following to my style sheet:
.nodisplay { display: none; } @media print { * { background-color: white !important; background-image: none !important; } .noprint { display: none; } }And then assign the noprint class to elements which shouldn't be printed:
<div class="noprint"> </div>And for your example, something like the following should work:
<img src="logo.png" class="noprint" ...> <h1 class="nodisplay">Text Logo</h1> -
Adding to Adam's solution: If your text is fixed ("head banner was there" not "ad for such and such was there"), you can use :before or :after pseudo-elements to insert text instead of having the text pre-inserted in the HTML.
I makes your HTML lighter if you are replacing many images with the same text.
I have to say that I dislike this CSS feature, but it is there if you want to use it.
-
According to CSS spec this should display the alt attribute after the image. Then you would just have to hide the image but I haven't managed to get it to work right in FF3 or chrome.
img:after{content: attr(alt);}