StringBuilder sample Example -1

Posted by Venkat | Labels: ,

Here we have to see the sample of stringbuilder ,

System.StringBuilder is mutable where variety of operations can be performed

System.String is immutable variable value may change BUT original data value will be discarded and new value will be in memory.

Add one listbox on your webform and add three items on design mode.

protected void Page_Load(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < array =" new" x =" this.ListBox1.Items[i].ToString();"> 0)
{
if ((builder.Length) != (ListBox1.Items.Count))
{

builder.Append(",");
// x += ",";
}
}

// Response.Write(builder);

}
string s = builder.ToString();
s = s.Substring(0, s.Length - 1);
Response.Write(s);
}

Get absolute path on tinymce Editor Control

Posted by Venkat | Labels:

Here we are going to discuss how to get the absolute path of the image or link on tinyMCE Editor contorl , by default it took relative path of the image so here it line you have to include on your script of your page.

relative_urls: false,

Watermark the textbox using javascript

Posted by Venkat | Labels: ,

Hi , Now we have to discuss about the watermark the textbox using javascript

for that you have to use onblur and onfocus property of your textbox


<script type = "text/javascript">

var defaultText = "Enter your text here";

function WaterMark(txt, evt)

{

if(txt.value.length == 0 && evt.type == "blur")

{

txt.style.color = "gray";

txt.value = defaultText;

}

if(txt.value == defaultText && evt.type == "focus")

{

txt.style.color = "black";

txt.value="";

}

}

</script>


Here is the HTML Code of the Textbox control

<asp:TextBox ID="TextBox1" runat="server" Text = "Enter your text here"

ForeColor = "Gray" onblur = "WaterMark(this, event);"

onfocus = "WaterMark(this, event);">

</asp:TextBox>

Now we have to write the attributes through code on your Page_load Event

TextBox1.Attributes.Add("onblur", "WaterMark(this, event);")

TextBox1.Attributes.Add("onfocus", "WaterMark(this, event);")

Textbox should allow minimum 5 Character

Posted by Venkat | Labels: ,

Hi Use this code.


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator
ID="valUserName" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="Minimum length 6 characters"
ForeColor="" ValidationExpression=".{6}.*" ></asp:RegularExpressionValidator>

Limit the Maximum number of Characters in the texbox

Posted by Venkat | Labels: , ,

Here is the code how to limit the no.of charater entered by the user in TextBox , mostly this can be implemented on Post comment , Feedback , Message board ...



This example demonstrates on how are we going to limit the number of characters to be typed into the TextBox using JavaScript and display the remaining characters in a Label Control.


<script type="text/javascript" language="javascript">

function validatelimit(obj, maxchar)
{

if(this.id) obj = this;

var remaningChar = maxchar - obj.value.length;
document.getElementById('<%= Label1.ClientID %>').innerHTML = remaningChar;

if( remaningChar <= 0)
{
obj.value = obj.value.substring(maxchar,0);
alert('Character Limit exceeds!');
return false;

}
else
{return true;}
}

</script>

<body runat="server">
<form id="form1" runat="server">

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" onkeyup="validatelimit(this,300)"> </asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="0"></asp:Label>

</form>

</body>
Note: 300 is the MAX length of the characters in the TextBox..Just change the value of 300 based on your requirements..

Clear all the control values in webpage

Posted by Venkat | Labels:

Here is the code to clear all the control values in the page. this function should call on Reset button Click event.


private void ResetFormValues(Control parent)
{
foreach (Control c in parent.Controls)
{
if (c.Controls.Count > 0)
{
ResetFormValues(c);
}
else
{
switch(c.GetType().ToString())
{
case "System.Web.UI.WebControls.TextBox":
((TextBox)c).Text = "";
break;
case "System.Web.UI.WebControls.CheckBox":
((CheckBox)c).Checked = false;
break;
case "System.Web.UI.WebControls.RadioButton":
((RadioButton)c).Checked = false;
break;

}
}
}
}

The same you can do it on JAVASCRIPT

Ex:

<input id="Button1" type='button' onclick='ClearAllControls()' value='Clear All Controls Using Javascript' />


<script language="javascript" type='text/javascript'>
function ClearAllControls() {
for (i = 0; i <>
doc = document.forms[0].elements[i];
switch (doc.type) {
case "text":
doc.value = "";
break;
case "checkbox":
doc.checked = false;
break;
case "radio":
doc.checked = false;
break;
case "select-one":
doc.options[doc.selectedIndex].selected = false;
break;
case "select-multiple":
while (doc.selectedIndex != -1) {
indx = doc.selectedIndex;
doc.options[indx].selected = false;
}
doc.selected = false;
break;
default:
break;
}
}
}
</script>

Editor controls

Posted by Venkat | Labels: ,

There are so many free editor controls Avaliable for .net control

http://www.freetextbox.com/
http://tinymce.moxiecode.com/
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HTMLEditor/HTMLEditor.aspx
I will post the each editor controls ,like how to declare and use it on ASP.NET etc..
Shortly...,

Installation of Freetexbox control

http://www.a2zdotnet.com/View.aspx?id=28
This is the Initialization of TinyMCE Editor control and you can also the downlaod the support folder

http://www.dotnetspider.com/resources/27037-TinyMCE-Editor-Control.aspx

Number of way pass the data between Webpages

Posted by Venkat | Labels:

Here is the link i have given , which shows the no. of way to pass the data between page like session,Querystring, Cross page Posting , etc..

http://dotnetslackers.com/Community/blogs/haissam/archive/2007/11/26/ways-to-pass-data-between-webforms.aspx

http://www.dotnetbips.com/articles/c585b4d3-93c5-4c66-9d49-8e1946f4d311.aspx

I will post the workout code shortly..,

Jump Link within Page

Posted by Venkat | Labels:

Here is the code how to switch the view like top or bottom

for ex: we have seen on FAQ pages there if we click top it goes to top of the page the same functionality we have to implement.

<asp:HyperLink ID="top" runat="server" />

<br />asdsadasdsadsadadas<br />

<asp:HyperLink ID="bottom" runat="server" NavigateUrl="#top" Text="top" />

or

<a id="identifier"> </a>
<br />asdhsa<br />asdjksahd<br />

<a href="#identifier"> to top</a>

How to Detect the user Close the page

Posted by Venkat | Labels:

You can use the onunload or the onbeforeunload events to execute codes when the browser is about to closed.

You may also use Page Methods, see below

http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.all

The code below will simulates the closed button of the browser when the user invoked the button and display an alert message..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function doSomething()
{
alert('Widnow is about to close');
}
</script>

</head>
<body onunload="doSomething();">
<form id="form1" runat="server">

</form>
</body&gt;

PayOffers.in