CoderBlog.NET
Tengiz Tutisani's blog.

 
Useful Links:
 
LanguageBox 
 
Language

 
SearchBox 
 
 
ArchiveBox 
 
Archive
<February 2012>
SuMoTuWeThFrSa
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
 
CategoriesBox 
 
Categories
  ASP.NET (5)
  Ajax (1)
  C# (7)
  Common (1)
  HTML (3)
  JavaScript (5)
  Products (1)
  SEO (1)
  SQL (1)
  Visual Studio (1)
  Windows (1)
 
FriendSitesBox 
 
Friend Sites
  AdMoney Project
  Cайт о гитаре и музыке!
  Design Studio IMAGINE
 
CustomContentBox [1] 
 



 
 
HTML Editing
How it works
Posted By:   tengo
At:   5/8/2009 9:55:00 AM
 

Did you know that almost any HTML control can be switched into edit mode? This effect can be achieved easily: just add CONTENTEDITABLE attribute to the component that must be an editor.

Place the following tag into the source of you HTML page and view it in browser:

<div CONTENTEDITABLE>some editable text</div>

As you can see, the text "some editable text" is editable now. In the easiest editing scenario, you can copy-paste the content from Word document to that editable area. For more complicated scenarios you can use document.execCommand method. (For advanced scenarios you can use a free and ready to use HTML editor tinyMCE).
Now let's talk about how you can get the content of that div as HTML. Depending on your needs, you can just get the content and do some operation with it. In my practice I had few situations when I wanted the content to be submitted to the server. As you probably know, only HTML input controls have ability to submit their values to the server. For this purpose, here I consider the code fragment that shows how to move the HTML value of the editable div to a Textarea control that actually can submit its value. The Input-button tag is added to move the content from one control to another.

<div id="text" CONTENTEDITABLE>some editable text</div>
<textarea id="content"></textarea>
<input type="button" value="get HTML content" onclick="content.value=text.innerHTML">

That's all, a little but sometimes very useful thing.
And one more: Button element can be created using not only the standard input tag, but also using a button tag like this:

<button value="some value">some text</button>

Note, that the button has a text "some text" instead of "some value" as you might think at a first look.

Thanks for your time.


Filed Under:   JavaScript | HTML |
Post Tags:   button | contenteditable | div | editor | html | javascript | submit | textarea | value |
  Comments [0]



 
 
Converting from string to int
Why not working (int)stringVariable?
Posted By:   tengo
At:   2/15/2009 11:15:00 AM
 

Converting from string to int
Why not working (int)stringVariable?


I was asked with this question. Well, I think there are a lot of professionals who will not even think about it, but my suggestion is, if there's a person who can ask such a question, there must be a person, who will find a time and answer it.

OK, I always love to answer using my own words, not the copy-paste magic from MSDN library (by the way, it can be found at http://msdn.microsoft.com).

In C#, the type can be explicitly converted to the type of the same type - a little complicated sentence, right? But the truth!
In this case, type int is a value-type, and type string is a reference-type. To convert from one to another, you must use static method int.Parse(string).

But be careful, it may throw an exception. If you want to handle the exception, you must use try-catch statement, or, a method that is more informational about parsing results, and as I think, more useful: int.TryParse(string, out int).
Let's consider next code:

string s = "123";
int number = int.Parse(s); //all's ok

s = "123a";
number = int.Parse(s); //exception is thrown!!!

//solution is:
//1)
try
{
number = int.Parse(s);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message); //or some other code to handle the exception
}

//2)
if (int.TryParse(s, out number);
{
//all's ok
}
else
{
MessageBox.Show("error converting from string to int"); //or some other code to handle the exception
}

That's all. I hope you cought the idea.

 


Filed Under:   C# |
Post Tags:   convert | csharp | exception | int | parse | reference | string | value |
  Comments [0]



 
CustomContentBox [2] 
 
Useful Links:
 
CategoryViewBox 
 
CoderBlog.NET
  Get your own Blog Engine
  SMS Sending Service
  What do you want to see on CoderBlog.NET?
  IMAGINE.GE created a header image for CoderBlog.NET
  CoderBlog.NET offers link exchange
  Quick language selection added
  CoderBlog.NET ‘s what is what
  Welcome to CoderBlog.NET

  Jump to Category...
 
TagsBox 
 
Popular Tags
aspnetblogcsharpdesigndivengineerrorformhtmljavascript
 
AuthorsBox 
 
Authors
  Tengiz Tutisani  (25)
 
SubscriptionsBox 
 
Subscriptions
Your Email:
 
LoginStatusBox 
 
Site Members
Login
 
Copyright © 2009 . CoderBlog.NET