Allow User to Enter Arabic Characters Or Number Only

July 24, 2016 Leave a comment

Dear all,

Try this example to Validate User to enter Arabic characters or numbers only

<asp:TextBox ID="txt_Name" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="rev_Name" runat="server" ErrorMessage="*" ControlToValidate="txt_Name" ValidationExpression="^[0-9\u0600-\u06FF/ ]+$" ></asp:RegularExpressionValidator>

Hope this helps

Good Luck.

Categories: ASP.Net

Set Maximum characters to 1000 for Multiline TextBox Using JQuery

July 22, 2016 Leave a comment

Hi all,

Try this example to Set Maximum characters to 1000 for Multiline TextBox Using JQuery


<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
 <script type="text/javascript">
 $(document).ready(function () {
 //Assign the text to span in pageload
 $('#spntxtMult').text("Number of characters 0/1000");
 //attach change event to div
 $('#txtMult').keyup(function (event) {
 //call function to calcualate count on change event of div
 textCounter();
 });
 });
 function textCounter() {
 //Get the max length countnt
 var divlength = $('#txtMult').val().length;
 //check if count greater than 1000
 if (divlength > 1000) {
 //Trim the text
 var trimmedtext = $('#txtMult').val().substring(0, 1000);
 //assign it to textbox
 $('#txtMult').val(trimmedtext);
 }
 else {
 var remaningchar = 0;
 //Calculate the remining char
 if (divlength > 0) {
 remaningchar = 1000 - divlength;
 }

//reduce the allowed no of characters in span
 $('#spntxtMult').text("Number of characters " + remaningchar + "/1000");
 }
 }
</script>
<asp:TextBox ID="txtMult" runat="Server" TextMode="MultiLine" />
<span id="spntxtMult"></span>

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript, Jquery

Debug ASP.NET Web Application hosted in IIS using Visual Studio

Hi all,

Try this example to Debug ASP.NET Web Application hosted in IIS using Visual Studio

1. Click the Tools menu in Visual Studio and click the item Attach Process.

Debug-IIS-ASP-Application

2. Search through the Available Processes with the name w3wp.exe.

Debug-IIS-Hosted-ASP-Application

3. Click the Attach button. Now you can watch your break point while doing relevant action in web page

Hope this helps

Good Luck

Categories: ASP.Net

Create An Error Log File

Hi all,

Try this example to Create an error log file

Step 1: Add a Global.asax file to Project/website if not exist.

Step 2: Now add the namespace to Global.asax file.

<%@ Import Namespace="System.IO" %>

Step 3: After that write the below given code in Application_Error event of Global file:

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
Exception ex = new Exception();
ex = Server.GetLastError().GetBaseException();
FileStream fs = new FileStream(Server.MapPath("~/ErrorLOG.txt"), FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, System.IO.SeekOrigin.End);
sw.WriteLine("ERROR DATE: " + System.DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture));
sw.Write("\r\n");
sw.Write("ERROR MESSAGE: " + ex.Message);
sw.Write("\r\n");
sw.Write("SOURCE: " + ex.Source);
sw.Write("\r\n");
sw.Write("FORM NAME: " + System.Web.HttpContext.Current.Request.Url.ToString());
sw.Write("\r\n");
sw.Write("QUERYSTRING: " + Request.QueryString.ToString());
sw.Write("\r\n");
sw.Write("TARGETSITE: " + ex.TargetSite.ToString());
sw.Write("\r\n");
sw.Write("STACKTRACE: " + ex.StackTrace + System.Diagnostics.EventLogEntryType.Error);
sw.Write("\r\n");
sw.WriteLine("-----------------------------------------------------------------------------------------");
sw.Close();
}

Hope this helps

Good Luck.

Categories: ASP.Net

Upload multiple files with ASP.Net 4.5

April 5, 2016 Leave a comment

Hi all,

Try this example to Upload multiple files with ASP.Net 4.5 in Visual Studio 2012 and Visual Studio 2013

ASPX Page :

<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg" />
<asp:Label ID="lblSuccess" runat="server" ForeColor ="Green" />

In Code behind :

protected void UploadMultipleFiles(object sender, EventArgs e)
{
foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
{
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
}
lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count);
}

Hope this helps

Good Luck.

Categories: ASP.Net

IIS 7 Blank Image Problem

March 15, 2016 Leave a comment

Hi all,

Try this to solve IIS 7 Blank Images Problem

static content

Hope this helps

Good Luck

Categories: ASP.Net

Removing Empty Spaces and HTML tags from TextBox text on Client Side

March 6, 2016 Leave a comment

Hi all,

Try this example for Removing Empty Spaces and HTML tags from TextBox text on Client Side

To remove spaces from textbox’s text in onblur event :

<asp:TextBox ID="TextBox2" runat="server" onblur="javascript:value=value.replace(/\s/g,'');"></asp:TextBox>

To remove HTML tags :

<asp:textbox id="TextBox2" runat="server" onblur="this.value = this.value.replace(/<\/?[^>]+>/gi, '');"></asp:textbox>

Hope this helps

Good Luck.

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.

Join 36 other followers