To get RadioButtonList Selected values and Text on Button Click using Javascript in asp.net page (.aspx page).
See the below example:-
Write the below javascript under header section of .aspx page
<script language="javascript" type="text/javascript">
function GetSelectedItem()
{
var RB1 = document.getElementById("<%=RadioButtonList1.ClientID%>");
var radio = RB1.getElementsByTagName("input");
var label = RB1.getElementsByTagName("label");
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked)
{
alert("SelectedText = " + label[i].innerHTML);
alert("SelectedValue = " + radio[i].value);
}
}
return false;
}
</script>
Call the above javascript function in asp button, to get selected radiobuttonlist Text,value:
<asp:Button ID="btnSubmit" Text="Submit" runat="server" CausesValidation="true"
ValidationGroup="General" OnClientClick="return GetSelectedItem();" />
Hope this is help full
Friday, November 19, 2010
Validate Radiobuttonlist using Javascript
This time i want to explain, How to validate RadioButtonList using javascript in asp.net.
In this below example i am going to explain to validate radiobuttonlist, to select at least one radio button.
Technology : asp.net ,HTML ,JAVASCRIPT
Please follow the below example :
Write the below javascript in asp.net page (.aspx) page header section.
<script type ="text/javascript" language="javascript">
function Validate() {
var RB1 = document.getElementById("<%=RadioButtonList1.ClientID%>");
var radio = RB1.getElementsByTagName("input");
var isChecked = false;
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("Please select an item");
}
return isChecked;
}
</script>
call the above javascript function on button click event as follows:
<asp:Button ID="btnValidateRadioList" runat="server" Text="Validate"
OnClientClick = "return Validate();"/>
Hope this is Help full
In this below example i am going to explain to validate radiobuttonlist, to select at least one radio button.
Technology : asp.net ,HTML ,JAVASCRIPT
Please follow the below example :
Write the below javascript in asp.net page (.aspx) page header section.
<script type ="text/javascript" language="javascript">
function Validate() {
var RB1 = document.getElementById("<%=RadioButtonList1.ClientID%>");
var radio = RB1.getElementsByTagName("input");
var isChecked = false;
for (var i = 0; i < radio.length; i++) {
if (radio[i].checked) {
isChecked = true;
break;
}
}
if (!isChecked) {
alert("Please select an item");
}
return isChecked;
}
</script>
call the above javascript function on button click event as follows:
<asp:Button ID="btnValidateRadioList" runat="server" Text="Validate"
OnClientClick = "return Validate();"/>
Hope this is Help full
Tuesday, November 16, 2010
File Upload control validation using Javascript
We often used to validate Fileupload control by file extension validation at server side.It is little bit time taking process but secure. If we want to validate file upload control with some known file extensions at client side, we need to use javascript.
See the below example to validate file upload control using javascript :
In aspx page header section just write the following javascript code:
<script type ="text/javascript">
// Declare known file extensions in an array
var validFilesTypes=["bmp","gif","png","jpg","jpeg","doc","xls"];
function ValidateFile()
{
var file = document.getElementById("<%=FileUpload1.ClientID%>");
var label = document.getElementById("<%=Label1.ClientID%>");
var path = file.value;
var ext=path.substring(path.lastIndexOf(".")+1,path.length).toLowerCase();
var isValidFile = false;
for (var i=0; i<validFilesTypes.length; i++)
{
if (ext==validFilesTypes[i])
{
isValidFile=true;
break;
}
}
if (!isValidFile)
{
label.style.color="red";
label.innerHTML="Invalid File. Please upload a File with" +
" extension:\n\n"+validFilesTypes.join(", ");
}
return isValidFile;
}
</script>
In aspx page body section :
<asp:fileupload id="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClientClick = "return ValidateFile();" />
<asp:Label ID="Label1" runat="server" Text="" />
Hope this is helpfull..!
See the below example to validate file upload control using javascript :
In aspx page header section just write the following javascript code:
<script type ="text/javascript">
// Declare known file extensions in an array
var validFilesTypes=["bmp","gif","png","jpg","jpeg","doc","xls"];
function ValidateFile()
{
var file = document.getElementById("<%=FileUpload1.ClientID%>");
var label = document.getElementById("<%=Label1.ClientID%>");
var path = file.value;
var ext=path.substring(path.lastIndexOf(".")+1,path.length).toLowerCase();
var isValidFile = false;
for (var i=0; i<validFilesTypes.length; i++)
{
if (ext==validFilesTypes[i])
{
isValidFile=true;
break;
}
}
if (!isValidFile)
{
label.style.color="red";
label.innerHTML="Invalid File. Please upload a File with" +
" extension:\n\n"+validFilesTypes.join(", ");
}
return isValidFile;
}
</script>
In aspx page body section :
<asp:fileupload id="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClientClick = "return ValidateFile();" />
<asp:Label ID="Label1" runat="server" Text="" />
Hope this is helpfull..!
Saturday, November 13, 2010
unable to copy file access to the path is denied
In visual studio while building on application you might get the following error.
unable to copy file ' c://xxx/xxx...' access to the 'D://xx/xxx..' path is denied.
The reason behind this is the current file is in read only mode.
You just do the following steps, then the problem will resolve.
unable to copy file ' c://xxx/xxx...' access to the 'D://xx/xxx..' path is denied.
The reason behind this is the current file is in read only mode.
You just do the following steps, then the problem will resolve.
- Go to the file copying file location or pasted location(In case if it is pasted and giving error) .
- Right click on that file a context menu will be open.
- Select properties.
- A new window will open with General tab.
- Under the general tab if Read only Permission is checked, just uncheck it.
- Now build the application. The build will succeed.
Subscribe to:
Posts (Atom)