on advise of one of my friend i’m now using the following code, following code is also working in template file but giving no result in my custom-widget or sidebar.php.
<?php // Get Current Page ID outside Loop
global $wp_query;
$post_obj = $wp_query->get_queried_object();
$Page_ID = $post_obj->ID;
echo $Page_ID;
?>
please if anybody now the problem, let me know. Thanks