Click here to Skip to main content
14,664,507 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear Friends,

I am new to javascript rather very new and i have to run a javascript function on the basis of what a function (server level code) at server side returns (true or false) but i am not able to do so.

for e.g. the method is checking that whether the selected item from the grid doesn't exists in the database then the user should get a prompt that "this item doesn't exists.Do you want to continue?".

Now this message box should only get popup when the above condition i.e., item doesn't exists in database is true else not.

Please help me.


Varun Sareen
Updated 14-Feb-11 21:02pm
Monjurul Habib 15-Feb-11 3:05am
need more clarification / share you code to help you out.
Varun Sareen 4-Mar-11 4:15am
I have a server level method which gets value i.e., TRUE, depending upon which i have to run the javascript code for the confirmBox and if the value is FALSE, then no confirmbox :)

Rate this:
Please Sign up or sign in to vote.

Solution 2

Try using Page.RegisterClientScriptBlock Method [^] OR Page.RegisterStartupScript Method[^]

Using them, you can inject the scripts into a page from server side and based on certain condition (and specific to page.)

For samples on how to use it: How to Use RegisterClientScriptBlock & RegisterStartupScript[^]
Sample 2[^]
Rate this:
Please Sign up or sign in to vote.

Solution 1

<script type="text/javascript">
function checkThis(x)
    if( x == number)
        return true;
        return false;


and after that you can call it from the body or where ever you want.
Varun Sareen 15-Feb-11 2:59am
kindly elaborate :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100