 |
|
 |
if ( document.forms[0].elements[e].type.indexOf("select") == 0 && document.forms[0].elements[e].name.indexOf(prefix + ":lstProperties") == 0 )
In the above line of Javascript code, in VS2003, the app was looking for a ':' as a delimiter. In VS2005, this code quit working, it was now looking for a '$'
":lstProperties" ====> "$lstProperties"
However, we have had circumstances where on a VS2003 app, it may be run on a different environment when deployed to anther server. (not ideal I know)
So I am looking for a system field that holds the value of this delimiter, so I can output it, and know what delimiter it is looking for.
smcirish
Texas
|
|
|
|
 |
|
 |
I think there is a better way to write your javascript. First the indexOf function should find your lstProperties when you have the prefix or not. Second if you are trying to figure out the control name it is usally better just to pass it into the javascript function.
So in your codebehind you have a controler lets call it lstProperties. In your code behind you can access what the control will be called in javascript. lstProperties.ClientID. This can be passed into your javascript function on assignment. For example:
btn1.Attributes.Add("onClick","yourJavascriptfunction('"+lstProperties.ClientID + "');")
Sorry if you didn't want VB.net syntax the C# isn't that different.
Now in your javascript function:
function yourJavascriptfunction(ctrl){
var tmp = document.getElementById(ctrl);
//other code here
}
Anyway, I don't know if that helps you or not.
Ben
|
|
|
|
 |
|
 |
Thanks Ben,
I am not that familiar with JavaScript, would you mind being a little more explicit?
Can you give me an example of use of IndexOf, to find the delimiter?
smcirish
Texas
|
|
|
|
 |
|
 |
You know, it is perhaps better if you fully explain what you are trying to accomplish in javascript and then perhaps I can help you figure out how to do it.
Ben
|
|
|
|
 |
|
 |
if ( document.forms[0].elements[e].type.indexOf("select") == 0 && document.forms[0].elements[e].name.indexOf(prefix + "<big>:</big>lstProperties") == 0 )
How do I update the line of code above, so I won't have to know whta the delimiter is?
":lstProperties")
smcirish
Texas
|
|
|
|
 |
|
 |
The above code doesn't tell me what you are trying to do. What is it that you are trying to do in javascript?
Ben
|
|
|
|
 |
|
 |
It is parsing out employee info, to display in a select box. The delimiter will vary based the environment the app is being run on. VS2003 vs. VS2005.
So I have trying to either find a way to determine the delimeter, or alter the code so in case the delimiter varies.
smcirish
Texas
|
|
|
|
 |
|
 |
Ok that helps. Why don't you control the delimiter of the employee info? Where are you getting the employee info from? I have some javascript code that splits out delimiting values and populates a dropdown.
NOTE you have to be careful when using javascript to update asp.net server controls. Sometimes when you post back on submit the changed data isn't there. In that case sometimes the best thing you can do is use hidden variables.
Ben
|
|
|
|
 |
|
 |
I cannot control the delimeter. I think it is a system field, because a different delimiter was used when the app was run on a different environment.
The app was created in VS2003, but it looked for : delimeter when it was run on a VS2003 environment.
and it looked for a $ delimiter when it was run on a VS2005 environment.
So, I just want to find a way to find out what the delimeter is, since it can change, based on the enviromnent.
smcirish
Texas
|
|
|
|
 |
|
 |
Ok, I still think there is a better solution for this, but here you go:
document.forms[0].elements[e].name.indexOf("lstProperties") != -1
So that code will return -1 if lstProperties can not be found anywhere in the name. If it exists in the name it will return back the index that text starts at.
Ben
|
|
|
|
 |
|
 |
Some Other Debugging Tips
|
|
|
|
 |
|
 |
I think that "side note : adding a "debugger;" line in code will also allow Javascript to be debugged. "
has been even more of a helpful comment.
You can just put debugger; and it will break in the javascript code.
Thanks dustkicker for that comment.
Ben
|
|
|
|
 |
|
 |
Thank you!
JavaScript - C# - MS Sql Server - asp.net 2
|
|
|
|
 |
|
|
 |
|
 |
If we make javascript file as embeded resource in asp.net or u can say web resoucre.How to debug them with out pain.I think u understand the men of pain.
Thanks
|
|
|
|
 |
|
 |
This solution should still work ok. I am pretty sure that the javascript must end up in the html of the page, so just because you embed it in a resoure, it will get pulled from the and put in the page when the page is sent to the browser. So this solution in the article would be able to debug that javascript. Now you still have the issue of fixing the javascript and embeding it again in the resource, but that is a different issue, you will be able to debug it.
Thanks,
Ben
|
|
|
|
 |
|
 |
Kubben,
You wrote:
"NOTE: you will find with script debugging enabled that many internet sites have lots of javascript problems. So I would suggest only turning this on when you want to debug your javascript otherwise you will be bothered by IE asking you if you want to debug other peoples bad javascript."
This is true, but I would not recommend toggling this on and off as you might wonder sometimes why the debugger is not firing. I know it sounds obvious to enable debugging in Internet Explorer (IE) , but I've seen it happen to many people and they never bother to check the obvious. A better idea is to have a windows account on your machine (your developer account) that has IE setup to be in debug mode for developing web applications. As well set your cache in Internet Explorer to the lowest number of MB possible. Also set your IE cache options to check "Every visit to the page".
Also be wary when debugging a static HTML page. If you make changes to a static HTML page, it doesn't always get updated, even with the above caching options set. I get around this by adding a querystring and changing it whenever I make changes to the HTML page. This only applies to you current browser session. If you close the browser and open the page again, it should be updated.
There is also a cool tool called the IE Developer Toolbar that you might want to check out, http://www.microsoft.com/downloads/details.aspx?FamilyID=E59C3964-672D-4511-BB3E-2D5E1DB91038&displaylang=en
This is all great if you're debugging only IE (probably a corporate scenario), however in the wonderful world of the Internet, more than IE needs to be supported.
Yes, I know IE still dominates, but 15% or whatever Firefox is at these days, is still a lot of people and Mac users are all about Safari or Firefox. Basically you want as many people seeing your site and seeing your site well.
Sooo....
Firefox has a cool add-on called FireBug, https://addons.mozilla.org/en-US/firefox/addon/1843, as well as another cool tool called the DOM Inspector which comes with Firefox by default.
You also might want to look into JSDoc, http://jsdoc.sourceforge.net, and JSUnit, http://www.jsunit.net, for speeding up development in the long run because you have API docs to reference and creating code that follows a certain standard.
Cheers,
Nick
|
|
|
|
 |
|
 |
Hey Nick,
Thanks for your note. I understand your warning about toogling the script debugging on an off, but I have really never had an issue. Since the menu item doesn't show up when script debugging is turned off, it is pretty ovious what the problem is.
You are correct about needing to worry about other broswers. I figure with most javascript, you still need to get it written in IE first and then start to work on the other browers you are wanting to support. I have seen the IE developer tool bar, thanks for including that link. I have used the native firefox debugging stuff, I haven't see firebug yet, I will have to check that out.
Anyway, thanks for all the links and your comments.
Ben
|
|
|
|
 |
|
 |
If your javascript is contained in a separate file (.js), you can put breakpoints and debug code if you are running the application locally. This allows you to take advantage of the immediate window, and other features of vs.
Also, Orcas (vs2007), enhances the debugging of Javascript in the IDE.
|
|
|
|
 |
|
 |
Thanks for the note and the tip. I didn't know that you could do that if the javascript was in a sepparate file. I still have a bit of code that is dynamically adding javascript with the startup scriptblock etc. so with that I still need to use the debugger in IE.
Thanks,
Ben
|
|
|
|
 |
|
 |
thank you for this suggestion.
stefano
|
|
|
|
 |
|
|
 |
|
 |
nice article
side note : adding a "debugger;" line in code will also allow Javascript to be debugged.
|
|
|
|
 |
|
 |
Glad you liked the article. Thanks for the tip on the adding the "debugger;" as another way to debug the Javascript.
Ben
|
|
|
|
 |
|
 |
I had no idea you could this in VS. Thank you!
|
|
|
|
 |