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

Filed in .Net 1 Comment

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 in .Net Leave a comment

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

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

Filed in .Net Leave a comment

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 in .Net Leave a comment

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

TOP