Displaying message in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shaileshsharma
    New Member
    • Jun 2007
    • 26

    Displaying message in c#

    Hi, I am displaying message in c# like this

    Response.Write( "<script>al ert( 'Sum is 50' )</script>");
    it is working fine,but it is not working when we take variable in aleart like

    int a=25;
    int b=25;
    int sum=a+b;

    Response.Write( "<script>alert( sum)</script>");
    this is not working.
    anyone can solve my problem.

    Shailesh Kumar
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Shaileshsharma
    Hi, I am displaying message in c# like this

    Response.Write( "<script>al ert( 'Sum is 50' )</script>");
    it is working fine,but it is not working when we take variable in aleart like

    int a=25;
    int b=25;
    int sum=a+b;

    Response.Write( "<script>alert( sum)</script>");
    this is not working.
    anyone can solve my problem.

    Shailesh Kumar
    Try
    [CODE=css] Response.Write( "<script>alert( ''+sum)");[/CODE]

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      sum is a variable in your c# code, not your javascript, so you will need something like:
      Code:
      int a=25;
      int b=25;
      int sum=a+b;
      
      Response.Write("<script>alert('"+sum.ToString()+"')</script>");
      Note: that inside the alert() I have included the ' on either side of the contents and not just a "
      (So it's a ' followed by a " then +sum.ToString() + then " then ' )

      Comment

      • TRScheel
        Recognized Expert Contributor
        • Apr 2007
        • 638

        #4
        Originally posted by Plater
        sum is a variable in your c# code, not your javascript, so you will need something like:
        Code:
        int a=25;
        int b=25;
        int sum=a+b;
        
        Response.Write("<script>alert('"+sum.ToString()+"')</script>");
        Note: that inside the alert() I have included the ' on either side of the contents and not just a "
        (So it's a ' followed by a " then +sum.ToString() + then " then ' )
        Wouldn't it be easier to just write it like:

        [code=cpp]
        Response.Write( string.Format(" <script>alert(' {0}')</script>", sum));
        [/code]

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Maybe, but I never liked the string formater. Reminds me too much of printf().

          Originally posted by TRScheel
          Wouldn't it be easier to just write it like:

          [code=cpp]
          Response.Write( string.Format(" <script>alert(' {0}')</script>", sum));
          [/code]

          Comment

          • TRScheel
            Recognized Expert Contributor
            • Apr 2007
            • 638

            #6
            Originally posted by Plater
            Maybe, but I never liked the string formater. Reminds me too much of printf().
            Ah, everyone has their quirks. I particularly like it. No right or wrong, I just thought in that example it would be easier to show what you were getting at like that.

            Comment

            Working...