SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing C# variable value to javascript alert

    In my c# program, I have a int variable recordNum. I have a javascript alert being called from c# program like this:
    btnLnk.Attributes.Add("onclick", "javascript:if(confirm('Do you really wish to delete record # ?') == false) return false;");

    How do I pass the value in my variable recordNum to this javascript alert so that it displays something like this: Do you really wish to delete record # 5?

    Thank You.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is just regular old string concatenation.
    http://www.danielsoper.com/programmi...rce.aspx?ID=19

  3. #3
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    It does not show the alert if I code it with string concatenation like this:
    btnLnk.Attributes.Add("onclick", "javascript:if(confirm('Do you really wish to delete record # '+counter+' ?') == false) return false;");


    But if I code it with just one string, it shows the alert:
    btnLnk.Attributes.Add("onclick", "javascript:if(confirm('Do you really wish to delete record # ?') == false) return false;");

    How can I make it show the value of the counter?

  4. #4
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops, I found my mistake. I was messing the quotes. The correct code is:
    btnLnk.Attributes.Add("onclick", "javascript:if(confirm('Do you really wish to delete record # "+counter+" ?') == false) return false;");


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •