Validation for Tiny_MceEditor Control

Posted by Venkat | Labels: , ,

Here is the code

validation for tiny_mceEditor control

here is the code for validate the (Required field validation ) for the control

< style="font-weight: bold;">OnClientClick="tinyMCE.triggerSave(false,true);"

Accept a Textbox of 1000 Characters Only

Posted by Venkat | Labels: ,

Suppose in a message board related to same point of view , we place the text with multiline = True.. so user can enter a number of paragraphs, so the user has to avoid more lines ( paragraph ) to allow only the specific Character here the Regular expression to allow only 1000 Characters

EGEX - Validataion Expression - [\\s\\S]{0,1000}$

Use Like Operator using Parameterize Queries

Posted by Venkat | Labels: ,

To use like operator using parametrized Queries suppose if we use the like ie: wild character "%" directly through the query.

There may be attach of Sql Injection - so we have to avoid.

Here is the sample code.

// 1 . using "Like" operator with plus sign in query :

string command = "Select Name from UsersTable1 where Name Like '%'+ @Name + '%' ";

SqlCommand cmd = new SqlCommand(command);

cmd.Parameters.AddWithValue("@Name", textBox1.Text);

// 2. using percentage sign when parameter assignments :

string command = "Select UserName from UsersTable2 where UserName Like @UserName";

SqlCommand cmd = new SqlCommand(command);

cmd.Parameters.AddWithValue("@UserName", string.Format("%{0}%", textBox1.Text));

Avoid execution of page While you Refresh

Posted by Venkat | Labels: , , ,

Hi , here we have to discuss the how to avoid the execution of code

While you refresh the page.. suppose if you have written the code for sending email to users.. after clicking the button the code has been executed suppose if youRefresh the same page once again the Email sent to the user so here we have to avoid the execution on code on page_Refresh

this is the code in VB.NET and C#

Vb.NET


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Session("CheckRefresh") = Server.UrlDecode(System.DateTime.Now.ToString())
End If
End Sub


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
If Session("CheckRefresh").ToString() = ViewState("CheckRefresh").ToString() Then
Label1.Text = "Hello"
Session("CheckRefresh") = Server.UrlDecode(System.DateTime.Now.ToString())
Else
Label1.Text = "Page Refreshed"
End If
End Sub

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
ViewState("CheckRefresh") = Session("CheckRefresh")
End Sub

Here in this code i m saving system date and time in session varaible when the page gets load and in the page prerender event , which occurs after page_Load event , i m assigning the value if session variable to viewstate varaible
Now in Button_Click Event i m checking if both the values in session variable and in ViewState varaible are same than page in not refreshed
if they are not same that means page has got refreshed

This is code for C#.NET


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
}
}


protected void Button1_Click(object sender, EventArgs e)
{
if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
{
Label1.Text = "Hello";
Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
}
else
{
Label1.Text = "Page Refreshed";
}

}

protected void Page_PreRender(object sender, EventArgs e)
{
ViewState["CheckRefresh"] = Session["CheckRefresh"];
}

PayOffers.in