I am building a multilingual web application in which i have a .aspx.cs file
public partial class example:System.Web.UI.Page
{
private string message="message to be displayed depending on user language";
public string Message
{
get{return message;}
set{}
}
}
and a .aspx file in which i have linked a javascript file for validating user input
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript" src="Scripts/DataValidation.js"></script>
</head>
<body>
<form id="form1" runat="server" onsubmit="return validation()">
<asp:TextBox ID="tbSupplierName" CssClass="marginspace" runat="server" Width="150px" MaxLength="30"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search"
onclick="btnSearch_Click" />
</form>
</body>
</html>
my DataValidation.js file loks like this
function validation()
{
var SupplierName = document.getElementById('tbSupplierName');
if (SupplierName.value.length == 0)
{
alert('please enter supplier name');//here i want to display server side variable 'message'
return false;
}
}
The problem is i want to pass my server side variable 'message' to the linked external javascript file DataValidation.js and display it in alert
I have tried below code but it is not working
function validation()
{
var message='<%=Message%>';
var SupplierName = document.getElementById('tbSupplierName');
if (SupplierName.value.length == 0)
{
alert(message);
return false;
}
}
Help me to solve the problem.Thanks in advance.