Server tags cannot contain constructs

I stumbled upon another issue. I am sure there is a good reason they decided to not allow this, but I found it quite frustrating to learn it the hard way. Server Control tags, like for a button, or TextBox or any other server control, can not contain .net code <% … %>. For example:

<asp:Button ID=”btnRefreshLayout” runat=”server” Text=”Refresh Layout” OnClientClick=”AdjustFrameDim(<%= _layout%>);” OnClick=”btnRefreshLayout_Click” />

The result is…

<input type=”submit” name=”btnRefreshLayout” value=”Refresh Layout” onclick=”AdjustFrameDim(<%= _layout%>);” id=”BI_TabControl1_ucLayout_btnRefreshLayout” />

It doesn’t seem to matter where in the server control code you put the <% … %>, it doesn’t work.

BUT, I have good news… If you need to dynamically add something to the properties of the server control, you could instead use the AddAttribute method of the server control and get the needed results that way.

btnRefreshLayout.Attributes.Add(“OnClick”, “AdjustFrameDim(“ + _layout + “);”);

Happy Coding.

Dynamically added UserControls not persisted.

I am not sure I gave this post an appropriate title, but it works for now.

The Problem:
ASP.Net gives a developer the opportunity to programmatically add controls to a web form using ParentControl.Controls.Add(new Control()); However, these controls are not persisted in any way thus having to be recreated for each subsequent request.

What I found:
On the page I have a PlaceHolder. Depending on the dynamic data at the time of processing, one of 10 “layout” UserControls need to be added to the PlaceHoder. And inside each of those “layouts” will be 2 to 4 “content” UserControls with dynamic data based on the data and properties set by the “layout” UserControl. While stepping Continue reading “Dynamically added UserControls not persisted.”

Modal Dialog for all.

I came across an interesting problem the other day. I was developing a way to have error dialog for our web application regardless of the web browser. I did not want to use the JavaScript alert message box. I could not use the IE Modal dialog. So I decided to display the error message in a DIV tag that would be centered on the screen and only made visible when there was an error. Then I thought, wouldn’t it be cool to be able to move the error dialog around the screen, in case it was covering up the form element that had a problem. I found dom-drag.js to be quite cool andListBox Example very helpful.

To make the DIV tag overlay the existing page, I needed to set the Z-index of the DIV at a higher level then anything else on the page. I soon found that no matter how hard you tried, all DropDownList boxes and List boxes would show through the error dialog.

After some research, I soon found that this is an issue with Internet Explorer and wasn’t much I could do about it. It is because DropDownList boxes and List boxes are considered a windowed component in the browser and regardless the z-index you assign these components or the DIV that contains them, they will always float to the top. This issue is resolved in IE7, but the idea of making all customers upgrade to IE7 was not acceptable.

Continue reading “Modal Dialog for all.”

Firefox Extensions

If you don’t use Firefox yet, you should. If you use Firefox but have not tried out any Extensions, you need to. Extensions for Firefox is one of the many benefits of using Firefox. Extensions, extend the abilities, functions, features of Firefox. Firefox extensions can be found here. They even have extensions they recommend here.

A few of my favorites are:

 

Adblock Plus by Wladimir Palant

Ever been annoyed by intrusive advertisements? Install Adblock Plus and select a filter subscription. If you encounter an ad your subscription does not take care of, right-click it and select “Adblock.” You will never download ads again!

Continue reading “Firefox Extensions”

Firefox 2

Well, FireFox 2 has been released and it is quite nice. For details on whats new in the release click here. Unfortunately a few of the Extensions I have used and come to like no longer work, but I am sure they will be updated to work soon.

Some highlights in the new release that look promising are:

  • Built-in phishing protection: Phishing Protection warns users when they encounter suspected Web forgeries, and offers to return the user to their home page. Phishing Protection is turned on by default, and works by checking sites against either a local or online list of known phishing sites.
  • Improved tabbed browsing: By default, Firefox will open links in new tabs instead of new windows, and each tab will now have a close tab button. Power users who open more tabs than can fit in a single window will see arrows on the left and right side of the tab strip that let them scroll back and forth between their tabs. The History menu will keep a list of recently closed tabs, and a shortcut lets users quickly re-open an accidentally closed tab.
  • Resuming your browsing session: The Session Restore feature restores windows, tabs, text typed in forms, and in-progress downloads from the last user session. It will be activated automatically when installing an application update or extension, and users will be asked if they want to resume their previous session after a system crash.
  • Inline spell checking: A new built-in spell checker enables users to quickly check the spelling of text entered into Web forms (like this one) without having to use a separate application.

powered by performancing firefox

Code Search

Often as a developer, I find myself needing to solve a new problem a new way. I am not one to buy code books, but rely a lot on online refrences. So today I stumbled upon and compiled a list of code search engines that I thought I would share with you. And if you stumble accross this posting and have a code search or resource not listed here, please let me know, so I may update the list.

http://codase.com/

http://www.CodeProject.com/

http://koders.com/

http://www.krugle.com/

http://programmingishard.com/

http://www.google.com/codesearch

http://labs.oreilly.com/code/

Atlas with inline or external JavaScript – Unknown Error

More issues with Atlas and your own client javascript.

Today I stumbled accross another isse of my own JavaScript causing errors with Atlas. Typically you place all your JavaScript in the HEAD of the document. So.. today I added the following function to my JavaScript in the HEAD of the page.

javascript_form_submit

Atlas - Unknown ErrorAfter adding this code, any click on the page that used an Atlas Update Panel, caused the discreet Unknown Error dialog box. After many attempts to discove what the problem may be, I moved the entire function to script tags with-in the BODY of the page. All worked fine, with no Atlas “Unknown Error”.

I decided to test another sceniario, and put all my JavaScript in an external file (I usually wait till I am finished with the page for this step) and included it from with-in the HEAD of the page. Again I tested the page and all worked fine with no Atlas “Unknown Error”.

I thought this error may have something to do with the partial rendering that Atlas is taking care of, but after my second test, I an not so sure any more. Either way, I believe it may be a better practice to put all JavaScript in an external .js file and include it in the HEAD of your page.

Insert attribute value quotes

Hey, just got a tip from a friend, Steve. This tip will help prevent the issue of double quotes or no double quotes around javascript for the language attribute.

In Visual Studio 2005, go to Tools>Options> Text Editor > HTML > Format > Check both:

  • “Insert attribute value quotes when typing”
  • “Insert attribute value quotes for formatting”

VisualStudioToolsOptions
This will ensure all attribute values, such as the javascript value of the language attribute is always surrounded with quotes.

Thank you Steve.

JavaScript or “JavaScript”

I found another issue using Atlas the other day. I was using Atlas UpdatePanel around a TreeView and had some java-script functions on the page elsewhere. All was going fine Tuesday evening, then Wednesday morning, I started getting a what appeared to be a java-script error message.

Atlas - Unknown Error

When debugging, I was able to confirm that Atlas was working, I could step through my server code and populate the tree, but when execution was back at the browser, I would get this error pop-up “Unknown Error”.

I had made very little changes that morning, but due to closing the file earlier, I was unable to use the Undo function. After much time and testing, I remembered that in the HEAD of the HTML document, I had added another java-script function and noticed that the <script> tag did not have the language set, so I had set language=javascript. In Visual Studio 2005, the context sensitive help is great, and after typing language= it prompts with a choice of languages, and when you choose the language it adds it to your code with out quotes.

Now most of the time I have found that it doesn’t matter if you have quotes or not around your values. But this time it made a big difference. I added the double quotes around javascript and tested the page again, and this time there was no error and everything worked fine.

Intrigued by this finding, I did some more testing and found that if I put the SCRIPT tags with java-script functions just below the BODY tag, it did not matter if I used language=javascript or language=”javascript”, both ways worked just fine with Atlas.

So, in the HEAD of the HTML document, I needed to use language=”javascript”, but in the BODY of the HTML, double quotes didn’t seem to matter.

Also, see my post in this thread:
http://forums.asp.net/thread/1363655.aspx

Blog at WordPress.com.

Up ↑