enable disable asp.net validators on drop down selection change client side

Filed Under (Uncategorized) by admin on 18-05-2012

JavaScript function:

function setValidations() {

var ddlst = document.getElementById(”<%=ddlPiggyback.ClientID%>”);

var Text = ddlst.options[ddlst.selectedIndex].text;

if (Text == ‘0′) {

ValidatorEnable(document.getElementById(”<%=rfvPiggybackComments.ClientID%>”), false);

}

else {

ValidatorEnable(document.getElementById(”<%=rfvPiggybackComments.ClientID%>”), true);

}

}

In drop down (aspx side)

<asp:DropDownList ID=”ddlPiggyback” runat=”server” onchange=”setValidations();”>

<asp:ListItem>0</asp:ListItem>

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

</asp:DropDownList>

Convert string value to enum

Filed Under (Uncategorized) by admin on 17-05-2012

(Enums.RequestType)Enum.Parse(typeof(Enums.RequestType), rblRequestType.SelectedItem.Text)

Setting a text in aspx file via getting value from global resource file

Filed Under (.Net, Uncategorized) by admin on 11-05-2012

Text=”<%$ Resources:Common, No_Record_Found %>”

Where Common is the resource file name and No_Record_Found is Key name in Common.resx file

AJAX Toolkit File upload asynch asp:AsyncFileUpload

Filed Under (Uncategorized) by admin on 04-05-2012

It is perfect control if you don’t have to update any label or gridview in it .cs method. It perfectly did any DB operations but won’t update the html.

<asp:AsyncFileUpload OnClientUploadError=”uploadError” OnClientUploadComplete=”uploadComplete”

runat=”server” ID=”AsyncFileUpload1″ Width=”400px” CompleteBackColor=”White”

UploadingBackColor=”#CCFFFF” ThrobberID=”imgLoader” OnUploadedComplete=”FileUploadComplete”

FailedValidation=”False” />

<asp:Image ID=”imgLoader” runat=”server” ImageUrl=”~/images/loader.gif” />

<br />

<asp:Label ID=”lblMesg” runat=”server”></asp:Label>

FileUploadComplete method:

string strfilename = System.IO.Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);

string strFullPath = Server.MapPath(Constants.General.RequestAttachmentsFolderName + lblRequestID.Text + “/”);

if (!System.IO.Directory.Exists(strFullPath))

{

System.IO.Directory.CreateDirectory(strFullPath);

}

AsyncFileUpload1.SaveAs(strFullPath + strfilename);

JavaScript:

<script type=”text/javascript”>

function uploadComplete(sender) {

$get(”<%=lblMesg.ClientID%>”).style.color = “green”;

$get(”<%=lblMesg.ClientID%>”).innerHTML = “File Uploaded Successfully”;

clearContents();

–alert(’before’);

__doPostBack(’<%= Button1.ClientID %>’, ”);

–alert(’after’);

}

function uploadError(sender) {

$get(”<%=lblMesg.ClientID%>”).style.color = “red”;

$get(”<%=lblMesg.ClientID%>”).innerHTML = “File upload failed.”;

}

function clearContents() {

var AsyncFileUpload = $get(”<%=AsyncFileUpload1.ClientID%>”);

var txts = AsyncFileUpload.getElementsByTagName(”input”);

for (var i = 0; i < txts.length; i++) {

if (txts[i].type == “text”) {

txts[i].value = “”;

txts[i].style.backgroundColor = “white”;

}

}

}

</script>

Useful links

http://www.aspsnippets.com/Articles/Using-ASP.Net-AJAX-Control-Toolkits-AsyncFileUpload-Control.aspx

http://www.aspsnippets.com/Blue/Articles/Clear-contents-of-AsyncFileUpload-Control-after-upload-and-page-revisit.aspx

http://www.codeproject.com/Articles/42865/AsyncFileUpload-Control-New-Control-in-Ajax-Contro

http://www.asp.net/ajaxlibrary/HOW%20TO%20Use%20the%20AsyncFileUpload%20Control.ashx

RegularExpressionValidator for File Upload not working in Firefox, works fine in IE and Chrome

Filed Under (.Net) by admin on 30-03-2012

I want to validate the file extension before uploading. To validate the file extention I was using below Expression

“^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.doc|.docx|.xls|.xlsx|.pdf|.jpg|.JPG|.jpeg|.gif|.png|.bmp)$”

Above expression was not working in Firefox whereas works fine in IE and Chrome. After some Google searching I found below expression which works fine in above mention three browsers

“(.*\.([dD][oO][cC]|[dD][oO][cC][xX]|[xX][lL][sS]|[xX][lL][sS][xX]|[gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG]|[bB][mM][pP]|[pP][nN][gG]|[pP][dD][fF])$)”

Below is the link from where I found the expression

http://stackoverflow.com/questions/810541/file-upload-with-regularexpressionvalidator-not-working-with-firefox-only-ie

Server.MapPath in Class Library type project

Filed Under (.Net) by admin on 29-02-2012

string strPath= System.Web.HttpContext.Current.Server.MapPath(“Conference.aspx”);
If still not working, include the reference System.Web.

Disable autocomplete on a specific field and on the whole form asp.net

Filed Under (.Net) by admin on 27-02-2012

<asp:TextBox ID=”txtAbstractTitle” runat=”server” ValidationGroup=”vsAbstractSerial”                                  MaxLength=”500″ Width=”200px” autocomplete=”off” ></asp:TextBox>

<form id=”Form1″ method=”post” runat=”server” autocomplete=”off”>

Redirect parent page from iframe via c# code asp.net

Filed Under (.Net) by admin on 23-02-2012

this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), “myUniqueKey”, “self.parent.location=’DEFAULT.aspx’;”, true);

Automatic redirection from Http to Https and vise versa using relative urls in asp.net

Filed Under (.Net, ASP.Net Configuration) by admin on 14-02-2012

A very nice contorl/project (recommend by my Chief Architect) for a very common problem which we all face when we need to secure only specific pages. Below is the link.

http://code.google.com/p/securityswitch/

I applied this in my production environment and it is working perfectly. All related issues are solvable/configurable.

Some useful email exchanges between me and Matt(the guy who made this) are added below as comments.

Let me summarize the steps (If your using Visual Studio 2010)

  1. Install-Package SecuritySwitch from VS > Tool > Extension Manager > Search “SecuritySwitch” install it, more details can be found on http://nuget.org/packages/SecuritySwitch.
  2. Above step set-up every thing for you for your development environment. (Put some attributes in you web.config, add some dlls etc)
  3. Now you need to specify your secure pages in web.config inside securitySwitch>paths>
  4. These are important attributes mode=”" baseInsecureUri=”" baseSecureUri=”"
  5. For the staging or production deployment please go through with the below comments.

jQuery image plugin

Filed Under (Uncategorized) by admin on 14-02-2012

http://leandrovieira.com/projects/jquery/lightbox/#

ads
ads
ads
ads