[VS2005] Textbox Auto Expand

Here is an example of auto expand a textbox.

1. Control declaration:

<asp:TextBox ID=”txtMsg” runat=”server”  TextMode=”MultiLine” style=”overflow:hidden” onkeyup=”AutoExpand(this, event)” Rows=”2″ />

2. JavaScript function:

function AutoExpand(txtBox, event)
{
if (event.keyCode == “13” || event.keyCode == “8”) {
var therows = 0
var thetext = document.getElementById(txtBox.id).value;
var newtext = thetext.split(“\n”);
therows += newtext.length

document.getElementById(txtBox.id).rows = therows;
return false;
}
}

[VS2005] Email Validation

Example syntax for email validation:
Regex reg = new Regex(@”[a-z0-9!#$%&’*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&’*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?”);

if (!reg.IsMatch(Request.QueryString[“email”].Trim()))
{
Response.Write(“?????????”);
Response.End();
}

[VS2005] Image as Input Parameter

Using image as an input parameter, this is how the syntax should be:
public string strAddTemplate(string strGameCode, byte[] TemplateImage, string strImagemap, string strUserCode, string strClientIP)
{
SqlConnection con = null;
string strReturnCode = “”;

try
{
con = SqlHelper.CreateConnection(_connectionString);

SqlParameter prmGameCode = new SqlParameter(“@i_chvGameCode”, SqlDbType.VarChar, 10);
prmGameCode.Direction = ParameterDirection.Input;
prmGameCode.Value = strGameCode;

SqlParameter prmImage = new SqlParameter(“@i_chvImage”, SqlDbType.Image);
prmImage.Direction = ParameterDirection.Input;
prmImage.Value = TemplateImage;

SqlParameter prmImagemap = new SqlParameter(“@i_chvImagemap”, SqlDbType.VarChar);
prmImagemap.Direction = ParameterDirection.Input;
prmImagemap.Value = strImagemap;

SqlParameter prmUserCode = new SqlParameter(“@i_chvUsrCode”, SqlDbType.VarChar, 20);
prmUserCode.Direction = ParameterDirection.Input;
prmUserCode.Value = strUserCode;

SqlParameter prmClientIp = new SqlParameter(“@i_chvClientIp”, SqlDbType.VarChar, 15);
prmClientIp.Direction = ParameterDirection.Input;
prmClientIp.Value = strClientIP;

SqlParameter prmoResult = new SqlParameter(“@o_intResult”, SqlDbType.Int);
prmoResult.Direction = ParameterDirection.Output;

SqlParameter prmoRemark = new SqlParameter(“@o_chvResult”, SqlDbType.VarChar, 200);
prmoRemark.Direction = ParameterDirection.Output;

SqlHelper.ExecuteNonQuery(con,
CommandType.StoredProcedure,
“dbo.adm_sp_tb_template_add”,
prmGameCode,
prmImage,
prmImagemap,
prmUserCode,
prmClientIp,
prmoResult,
prmoRemark);

strReturnCode = (prmoResult.Value.ToString()) + “|” + (prmoRemark.Value.ToString());
}
catch (SqlException ex)
{
return ex.Message.ToString();
}
finally
{
SqlHelper.CloseConnection(con);
}
return strReturnCode;
}