ASP Textbox Not Updated; User Input Not Captured

I was playing with MS SQL just now and I encounter a problem when I would like to update a table in database. It later turned out that the problem was not in my UPDATE statement, but due to the fact that the user inputs in ASP textboxes are “not captured”.

Let me simplify the scenario. I have one textbox and one submit button.

<asp:TextBox ID=”tb_editName” runat=”server” Width=”432px” Text=”<%# retrieveInfo() %>”></asp:TextBox>

<asp:Button ID=”btn_editInfo” runat=”server” Text=”Save” onclick=”btn_editInfo_Click”/>

Here is part of the CodeBehind of the page:

protected void Page_Load(object sender, EventArgs e)
{

DataBind();

}

protected string retrieveInfo()
{

tb_editName.Text = “Kagami”;

}

protected void btn_editInfo_Click(object sender, EventArgs e)
{

//update the table with UPDATE statement

}

If I entered a value, for example “Konata”, into the textbox tb_editName and then clicked the button btn_editInfo, the UPDATE statement will always update the table in database with the value “Kagami”, instead of the user input “Konata”.

I searched on Google and then found the following online discussion: http://forums.asp.net/t/1104590.aspx/1. They said the problem was due to the fact that the Page_Load event would be fired in each postback.

Ah-ha! I found the solution: Using Page.IsPostBack. So basically I just need to make sure my table is updated before the DataBind() is called. Yup, after I have done that, everything is working fine again. =)

What about >=2 Buttons?
The example above has only 1 button. So, will there by any different if we have two or more buttons? The answer is yes.

Page.IsPostBack does not say anything about which button is pressed. So, to handle the cases where we have two or more buttons, we should have a change in the code organization shown above. A detailed discussion can be found here: http://p2p.wrox.com/asp-net-3-5-basics/79502-how-check-if-button-clicked-asp.html. Page_Load should have only the code which needs to be executed every time when the page loads. The actions that need to be carried out after a button is clicked should still be handled in the click event of the button.

Ah… I see.

Adding CSS3 to Visual Studio 2010 CSS Validation

I always edit CSS in Dreamweaver or Notepad (My friends always scream when they see me using Notepad to write CSS or HTML). Recently, I’m writing a web app to be deployed on Azure. So, I have the chance to edit CSS in Visual Studio 2010.

Visual Studio also provides us CSS validation. However, soon I found that VS kept warning me for having unknown CSS property names. I guessed that was due to the fact that it’s using an older CSS version for validation. Yappari, the “CSS Version for Validation” dropdown list showed that it’s currently using CSS 2.1. Thus, VS didn’t know the new property names introduced in CSS 3.

Warning (CSS 2.1): Unknown CSS Property Names
Warning (CSS 2.1): Unknown CSS Property Names

To solve that, I followed the steps suggested by Garry in StackOverflow. What I need to do is basically just downloading and then installing the “CSS 3 Intellisense Schema” (Free!) from VS extensions gallery: http://visualstudiogallery.msdn.microsoft.com/7211bcac-091b-4a32-be2d-e797be0db210.

Download CSS 3 Intellisense Schema for Free
Download CSS 3 Intellisense Schema for Free

In the discussion forum, there is a user, Nibblersrevenge, saying that if the CSS 3 validation entry was enabled even after the installation, we should copy the file “css30.xml” from the folder “C:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\1033\schemas\CSS” to the folder “C:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\1031\schemas\CSS”. Luckily, I didn’t encounter this problem.

After the installation is done, I can see the newly added CSS 3.0 option being added to the CSS validation dropdown. The warnings previously generated by VS are all gone after I change the CSS validation to CSS 3.0. Yay.

EDIT (27 April 2013): As iamprabhanshu pointed out in the comments section, if the CSS 3.0 option is still not available in the dropdown list after the installation, please  close the Visual Studio and re-open it.

No Warning in Validation with CSS 3.0
No Warning in Validation with CSS 3.0

No Permission to Create Database in SQL Server 2008 R2

This morning, I was playing with Microsoft SQL Server since I was asked by my senior to learn using it before going to work in next week.

I thought I had the free Express version. However, when I searched through the programs list, I found out that I actually had Microsoft SQL Server 2008 R2 in my computer. Yay~ I guess I got it for free from school. Thanks MSDNAA for helping SoC students that much!

I was very happy until I run the program. When I was about to create a database, I just found that I had no permission to do so. Oh my tian… I even forgot the password that I set that time (Wait… Did I even set a password?). I looked at the users list (/Security/Logins), I only saw BUILTIN\Users and sa. Ano… Where was the BULTIN\Administrators? I later found out that due to security issues, new SQL Server 2008 no longer had BUILTIN\Administrators in the SQL Server sysadmin fixed server role (Reference: Database Engine Configuration – Account Provisioning). Also I couldn’t access using SA account because I forgot the password that I set a long, long time ago.

Besides, I also could not create new user. That was quite disappointing.

CREATE DATABASE Permission Denied
CREATE DATABASE Permission Denied

Later, I read a thread on StackOverflow about resetting the SA password: http://stackoverflow.com/questions/4188193/how-do-you-reset-the-sa-password. Their problems were very similar to mine. Although it was about resetting the SA password, I guess if I could reset the password, I should have no problem accessing the databases as well.

Hence, I decided to try out their suggestions: Starting SQL Server in single-user mode. To do so, after closing the SQL Server Management Studio window, I launched SQL Server Configuration Manager. From there, I looked for the SQL Server instance. I then right-clicked on it go to Properties.

Step 1: Right-click Server Instance, Select Properties
Step 1: Right-click Server Instance, Select Properties

In the Advanced tab, I entered parameter “-m;” before existing parameters in “Startup Parameters”.

Step 2: Add -m as Parameter
Step 2: Add -m as Parameter

Finally, I clicked on OK and then restarted the server instance.

Step 3: Restart Server Instance
Step 3: Restart Server Instance

After that, I run SQL Server Management Studio again. Then I saw the following error message when I tried to connect with Windows Authentication.

Error: Only One Admin Can Connect At One Time
Error: Only One Admin Can Connect At One Time

Soon, I found that it won’t show this error message if I run SQL Server Management Studio as administrator as shown below.

Run SQL Server Management Studio as Administrator
Run SQL Server Management Studio as Administrator

Yup, now I can successfully create databases, add new users and reset passwords. =)

Now, it is time to remove the “-m” parameter.

In fact, there are online tutorials about starting SQL Server instance in single-user mode, for example http://blog.sqlauthority.com/2009/02/10/sql-server-start-sql-server-instance-in-single-user-mode/

Oh yeah, if there is a need to login SQL Server Management Studio with SA account, I can enable it in the Login Properties of the SA account (Reference: http://anujyadavcse.blogspot.com/2010/08/login-failed-for-user-sa-reason-account.html).

Enable SA Login
Enable SA Login

Playing with HTML 5: The Video Tag

I was playing with HTML5 again. Today, I was trying to use the new tag <video> to embed the intro video of the game Planetarian. I tried a few times using JS to detect the end of the video but only realized the correct way of doing it is as follows.

var video = document.getElementsByTagName(‘video’)[0];
video.addEventListener(“ended”, function() { //Do stuff here after end of video }, false);

According to online resources, this code should work in Chrome, Firefox as well as IE9! =D

Unfortunately, I just uninstalled IE9, so I haven’t tested it on IE9. =P

Intro Video of My Online Planetarian
Intro Video in My Online Planetarian