Tuesday, April 21, 2020

#if DEBUG Preprocessor Directive on ASP.NET Web Forms Markup

I have a JavaScript that I want to include only on Release mode of my ASP.NET Web Forms app. The script will reside in the markup. To do that I will need to use #if DEBUG. But to have it working in the markup takes me a while to figure out.

Problem

First, I tried wrapping my script with the following code on the markup under <head> tag and it doesn't work.

<% #if !DEBUG %>
<script>
alert('Hello World!');
</script>
<% #endif %>

Next, after reading some articles online, I tried to wrap my code using the following code and it still doesn't work.

<% if (!Debugger.IsAttached) { %>
    <script>
        alert('Hello World!');
    </script>
<% } %>

Solution

Finally, the one that works for me is when I wrap the whole thing with <asp:PlaceHolder> tag:

<asp:PlaceHolder runat="server"> 
<% #if !DEBUG %>
    <script>
    alert('Hello World!');
    </script>
    <% #endif %>
</asp:PlaceHolder>

Monday, April 6, 2020

Samsung Smart Switch Stuck When Updating Firmware on S20+

My old phone is dying so I got an S20+. The data transfer from old phone is easy, thanks to Samsung Smart Switch. However, even though the phone notified there was an OTA update, it can't download the update. While searching online for solution, I found out that Smart Switch PC can apply the update, so I give that a try.

Problem

Smart Switch recommends using Samsung original cable, so I use the USB-C to USB-C cable that comes with the S20+. It works well to a point, phone was detected, firmware downloaded, but in my case, it is stuck at 86% for hours. Some people in the forum said, it can take up to 30 minutes. So, this is not normal.

During the update, there is an option to cancel by pressing Volume down and Power key. However, that soft-brick the phone and I have to do Emergency Recovery. If you are also at this point, do jot down the "recovery code". I try the Emergency Recovery only to find out, it is also stuck at 86%. I tried two more times with the same result. Not good.

One option in the online forum is using Odin to flash. So, just in case I need it, I downloaded the latest version suggested in SamMobile. It is the 3.14.4. However, some people say that is not a clean version. And some people reported flashing S20s successfully with 3.13.1 patched version. I also downloaded the firmware which happened to be 5GB just in case I really need Odin. Needless to say, I'm not very fond of using non-recommended tools as my phone was just a day old.

Solution

At this point, Smart Switch can still detect the phone, so there is hope. I happened to read that one person in the online forum says he doesn't trust USB-C to USB-C cable due to its driver. That made me think of another option, how about if I switch the cable to USB-C to USB-A? Since USB-A has been around longer, the driver is more mature/time-tested. So, I ran Smart Switch again, not hoping much, but to my surprise, it passed the 86% mark and ended up flashing the firmware successfully. My phone is back! Praise God! Hallelujah!

So, try using USB-C to USB-A cable.