Fog Creek Software
Discussion Board

Is this code recommended?

// Use a StringBuilder to append strings
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append ("<script language=JavaScript> ");
sb.Append ("function ConfirmDeletion() {");
sb.Append ("return confirm('Are you sure you wish to delete employee: " + empID + "');}");
sb.Append ("</script>");
string js = sb.ToString();
if (!IsClientScriptBlockRegistered("ConfirmDeletion"))
RegisterClientScriptBlock("ConfirmDeletion", js);

This is some ASP.Net code that an article recommended in order to get a 1 line javascript function into an html page.

I've been playing around with ASP.Net projects, and it seems like the IDE is geared towards doing everything on the when I'm in the form designer and I double click on a brings up code to handle the event on the server side...

I tend to handle many things on client-side since most of my apps are for intranet use (IE only, which makes it easy to do neat client-sided tricks).  I find that handling as much as possible in the browser makes the applications more responsive, so right now I just use ASP as a proxy to the DB and other servers.

I really like the designer and IDE that Microsoft has put together for web applications, but is it geared towards this coding style?  If not, what would you recommend?  I currently use Dreamweaver since it offered more to me than the Visual Interdev previously did, but I'm shopping around.

Tuesday, March 30, 2004

But then, if this app is for intranets and IE, why not write the whole application as an ActiveX control in VB, so you don't have to worry about HTML and server-side scripting?

Tuesday, March 30, 2004

ASP/HTML is a very good model for certain tasks, especially for things that need to be built and deployed *quickly*. 

I have made OCX applications where appropriate, (usually because better COM controls than what HTML has to offer were available to do the job). 

Web stuff we usually do for quick solutions that many clients need.

Wednesday, March 31, 2004

For static javascript I just put the functions in the html - I think it's more readable. If the function is called from the codebehind, then I put a code comment indicating that the function can be found in the .aspx page.

I only emit javascript from the codebehind when it has to be dynamically created, like when control names are involved.


Wednesday, March 31, 2004

I agree.  However, I guess what I'm saying is that editing the HTML is no fun when you start getting above 7 or so functions in one page.

Even if you pack common functions in a .js file, there is no editor in .Net to help you edit these intellisense, no automated wizard code, etc.

I would like the designer to generate this code when I double-click the new button that I just layed out, instead of the equivalent server-sided code that get's generated:

function btnTest_OnClick(){
  ...cursor here after double click...
//#Region " Web Form Designer Generated Code "
function Window_OnLoad(){
//#End Region

I'm having a hard time understanding why they generate code to handle the event on the Server side.  For instance, when you drop a button in the's a submit button (haven't figured out how to change that one yet).

Wednesday, March 31, 2004

*  Recent Topics

*  Fog Creek Home