locked
using ASP.NET inline expressions RRS feed

  • Question

  • User-1559684635 posted

    Hi 

    May I know if I can use script tag in inline expression (ASP .Net Web Application web form)?

    I tried this but script tag does not exist. I know work in razor syntax

    <%

    if (Session["Type"].ToString() == "Delete")

    {

    <script type = "text/javascript" > alert(cc');</script>

    }

    %>

    Reference:

    https://support.microsoft.com/en-us/help/976112/introduction-to-asp-net-inline-expressions-in-the-net-framework

    Wednesday, June 20, 2018 3:43 PM

All replies

  • User753101303 posted

    Hi,

    This is not Razor. What if you try :

    <%
    if (Session["Type"].ToString() == "Delete")
    {
    %>
    <script type = "text/javascript" > alert(cc');</script>
    <%
    }
    %>

    ie as shown in your link you have to explicitly open and close each programming language part. I always stayed away from that. For example you could use  https://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript(v=vs.110).aspx to register a script from your code behind without having to change your ASPX markup.

    If your final goal is to ask confirmation before deleting something it is simpler to ask this client side right away when the UI element is clicked rather than going through multiple postbacks to handle the confirmation process.

    Wednesday, June 20, 2018 6:09 PM