Because
TempData["notice"]
is not accessible in Javascript directly. Because ASP.NET parts of the code execute on the server. JavaScript is executed in the browser. The server just sees the JavaScript as text, it is meaningless and non-functional. Only when the browser receives the page and interprets the JS is it executed.
Try to use something link that, to access the c# variable in javascript.
<script>
var myArray = <% = new JavaScriptSerializer().Serialize(TempData) %>;
if(myArray['notice']!=null){
alert("Success");
}
</script>
Hope it will helpful for you, please don't forget to mark my good rating. Thanks :)