Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. problem in calling a function according to condition specified

problem in calling a function according to condition specified

Scheduled Pinned Locked Moved ASP.NET
javascripthelpcsharpjavacryptography
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Miss Maheshwari
    wrote on last edited by
    #1

    hello i m calling a javascript function on page load like...

    Page.RegisterStartupScript("abs", "<script language=\"JavaScript\"> printAlert();</script>");

    and my java script function is...

    function printAlert()
    {
    var check=confirm("Do You Want To Print The Certificate");
    print(check);
    return check;
    }

    function print(res)
    {
    var color;
    if(res==true)
    color= document.getElementById("<%=btnPrint.ClientID%>").bgColor="red";    
    }
    

    and on page load i m calling another funtion like

        if (btnPrint.BackColor.ToString() == "red")
        {
            myC#function();
        }
    

    </pre>

    js function is working fine but on page load btnPrint.BackColor is always showing empty...so my c# function is never called.... please someone help

    C 1 Reply Last reply
    0
    • M Miss Maheshwari

      hello i m calling a javascript function on page load like...

      Page.RegisterStartupScript("abs", "<script language=\"JavaScript\"> printAlert();</script>");

      and my java script function is...

      function printAlert()
      {
      var check=confirm("Do You Want To Print The Certificate");
      print(check);
      return check;
      }

      function print(res)
      {
      var color;
      if(res==true)
      color= document.getElementById("<%=btnPrint.ClientID%>").bgColor="red";    
      }
      

      and on page load i m calling another funtion like

          if (btnPrint.BackColor.ToString() == "red")
          {
              myC#function();
          }
      

      </pre>

      js function is working fine but on page load btnPrint.BackColor is always showing empty...so my c# function is never called.... please someone help

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Have you stepped through using firebug/firefox to see if the js is doing what you expect it to ? Is bgColor the right property here ? Or is it blah.style.bgColor ? js just invents properties the first time you access them.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      M 1 Reply Last reply
      0
      • C Christian Graus

        Have you stepped through using firebug/firefox to see if the js is doing what you expect it to ? Is bgColor the right property here ? Or is it blah.style.bgColor ? js just invents properties the first time you access them.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        M Offline
        M Offline
        Miss Maheshwari
        wrote on last edited by
        #3

        when i m doing ok on confirm box it is showing red on alert(color); but my c# function is not calling...please help me....i have also tried through...

        .style.backgroundColor="red";

        it is changing the button's color but my motive is not to change the button's color....i want to call my c# function on basis of my condition...

        if (btnPrint.BackColor.ToString() == "red")
        {
        myC#Function();
        }

        but its not working... please help me

        C 1 Reply Last reply
        0
        • M Miss Maheshwari

          when i m doing ok on confirm box it is showing red on alert(color); but my c# function is not calling...please help me....i have also tried through...

          .style.backgroundColor="red";

          it is changing the button's color but my motive is not to change the button's color....i want to call my c# function on basis of my condition...

          if (btnPrint.BackColor.ToString() == "red")
          {
          myC#Function();
          }

          but its not working... please help me

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          If you do a postback, does it stay red ? If not, then the property is not stored in viewstate. If so, then I'd create a control and set the BackColor property in the aspx. Then I'd run the page, view the source, and see exactly what property ASP.NET is setting in the control. At the end of the day, I'd still lean towards using a hidden field.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          M 1 Reply Last reply
          0
          • C Christian Graus

            If you do a postback, does it stay red ? If not, then the property is not stored in viewstate. If so, then I'd create a control and set the BackColor property in the aspx. Then I'd run the page, view the source, and see exactly what property ASP.NET is setting in the control. At the end of the day, I'd still lean towards using a hidden field.

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            M Offline
            M Offline
            Miss Maheshwari
            wrote on last edited by
            #5

            my problem is still a problem....please someone help

            C 1 Reply Last reply
            0
            • M Miss Maheshwari

              my problem is still a problem....please someone help

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              I did. What happened when you did what I suggested ?

              Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              M 1 Reply Last reply
              0
              • C Christian Graus

                I did. What happened when you did what I suggested ?

                Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                M Offline
                M Offline
                Miss Maheshwari
                wrote on last edited by
                #7

                i tried that through hidden field....and on step by step debugging i checked that also...it is first compiling these lines...

                if (btnPrint.Value.ToString() == "1")
                {
                myC#function();
                }

                and after that javascript function so my c# function is never called please give me a solution

                C A 2 Replies Last reply
                0
                • M Miss Maheshwari

                  i tried that through hidden field....and on step by step debugging i checked that also...it is first compiling these lines...

                  if (btnPrint.Value.ToString() == "1")
                  {
                  myC#function();
                  }

                  and after that javascript function so my c# function is never called please give me a solution

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  The solution is to debug your javascript - did you get Firebug and Firefox as I suggested ?

                  Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                  1 Reply Last reply
                  0
                  • M Miss Maheshwari

                    i tried that through hidden field....and on step by step debugging i checked that also...it is first compiling these lines...

                    if (btnPrint.Value.ToString() == "1")
                    {
                    myC#function();
                    }

                    and after that javascript function so my c# function is never called please give me a solution

                    A Offline
                    A Offline
                    Arindam Tewary
                    wrote on last edited by
                    #9

                    Hi I am sure what Gauss suggested is the way you must address the issue. Open your web page in Mozila FireFox ( this is just a browser like Internet Explorer but helps a lot for debugging Javascript error. ) and idntify which line of your JS code creates the problem !!!

                    Thanks, Arindam D Tewary

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups