Saturday, February 20, 2010

How to pass server values to Javascript using Eval()

2 comments
In my application I have a target to show message if user does not have permission to navigate to another page. I can do this by using server code but it will make a round trip to server and make a bad user experience so, I decided to use java script.

Following is the function of Java Script

<script language="javascript" type="text/javascript">
function func_Message(obj)
{
if (parseFloat(obj)>0)
{
return true;
}
else
{
alert("Please assign a value before viewing the details");
return false;
}
}
</script>


And following is the code of Link Button from where I am passing value to Java Script Function

<asp:LinkButton ID="lnk_Details" runat="server" Text="Details" CommandArgument='<%# Eval("festi_id") +"~" + Eval("user_id") %>'
CommandName="ViewDetails" OnClientClick='<%# "return func_Message(" + Eval("user_id") + ");"%>'></asp:LinkButton>

2 comments:

請不要走 said...

我們不是因為快樂而歌唱,而是唱歌使我們快樂..................................................

IT Solutions said...

One of the very best weblogs I’ve come across for information and facts within this particular specialized niche. I will be coming back continually for unique blog posts.

Great Solution!