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. link ASP.NET function from HTML

link ASP.NET function from HTML

Scheduled Pinned Locked Moved ASP.NET
javascriptquestioncsharphtmlasp-net
12 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.
  • R Offline
    R Offline
    R Thomas 0
    wrote on last edited by
    #1

    hi... can somone pls tell me how can i link an ASP.NET function from HTML code?? like when i need to lik to a JS code i do this <~a href=""javascript:SortHeader();"">Status(Active/Inactive)<~/a~>(without the ~) so what should i do if i need to link to an ASP.NET function?? my asp.NET function resides in a MyFunction.vb and the function name is callHeader can someone pls tell me how can i call- myfunction.callHeader from html code to make a link from ?? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

    K M 2 Replies Last reply
    0
    • R R Thomas 0

      hi... can somone pls tell me how can i link an ASP.NET function from HTML code?? like when i need to lik to a JS code i do this <~a href=""javascript:SortHeader();"">Status(Active/Inactive)<~/a~>(without the ~) so what should i do if i need to link to an ASP.NET function?? my asp.NET function resides in a MyFunction.vb and the function name is callHeader can someone pls tell me how can i call- myfunction.callHeader from html code to make a link from ?? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

      K Offline
      K Offline
      killerslaytanic
      wrote on last edited by
      #2

      Hello: Actually you can´t call it directly. If Your intention is (and i guess it´s not) to execute that function without doing a postback, you just can't do that. (I interpreted that the function you want to call is a .NET one -should run at server side- not a client one) Now what yo can do is to use a Webform LinkButton control and on it´s OnClick event handler call the funtion you want to execute (there can be other approaches but that´s the simplest)

      R 1 Reply Last reply
      0
      • K killerslaytanic

        Hello: Actually you can´t call it directly. If Your intention is (and i guess it´s not) to execute that function without doing a postback, you just can't do that. (I interpreted that the function you want to call is a .NET one -should run at server side- not a client one) Now what yo can do is to use a Webform LinkButton control and on it´s OnClick event handler call the funtion you want to execute (there can be other approaches but that´s the simplest)

        R Offline
        R Offline
        R Thomas 0
        wrote on last edited by
        #3

        you are correct.. its a dotnet function and its a server side function too... but i dont want to use a button... i have to use a link... anyway i can achieve this through a link instead of a button?? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

        K 1 Reply Last reply
        0
        • R R Thomas 0

          you are correct.. its a dotnet function and its a server side function too... but i dont want to use a button... i have to use a link... anyway i can achieve this through a link instead of a button?? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

          K Offline
          K Offline
          killerslaytanic
          wrote on last edited by
          #4

          Ok but the LinkButton looks like a link ...it IS a link (the Button part of the name is ´cause it has the CommandName & CommandArgument properties just as buttons has them but for nothing else). If you insist in using a "real" link then you "only" have to attach its href to some javascript function in which you fill the value of a hidden field ,and submit the form by your own, Then in code behind ask for that value in the Page_Load, and if the value is set you execute your function... ...As you can see it is a very dirty solution but the Hyperlink control and the ones you can make in html through the format menu don´t have events associated and they don´t do postbacks to the server when clicked...so other approaches should be similars to this one... if someone has a cleaner way, please post it. My suggestion : use the LinkButton control and you'll only need a single line of code in which you´ll call your function.

          R 1 Reply Last reply
          0
          • R R Thomas 0

            hi... can somone pls tell me how can i link an ASP.NET function from HTML code?? like when i need to lik to a JS code i do this <~a href=""javascript:SortHeader();"">Status(Active/Inactive)<~/a~>(without the ~) so what should i do if i need to link to an ASP.NET function?? my asp.NET function resides in a MyFunction.vb and the function name is callHeader can someone pls tell me how can i call- myfunction.callHeader from html code to make a link from ?? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

            M Offline
            M Offline
            Mazdak
            wrote on last edited by
            #5

            You can do it easily Josesh, I don't rememeber the exact syntax now but its something like this: [/> Maybe others correct this or you can find correct syntax with googling.](<%#functionnameincodebehind()%)

            R K 2 Replies Last reply
            0
            • K killerslaytanic

              Ok but the LinkButton looks like a link ...it IS a link (the Button part of the name is ´cause it has the CommandName & CommandArgument properties just as buttons has them but for nothing else). If you insist in using a "real" link then you "only" have to attach its href to some javascript function in which you fill the value of a hidden field ,and submit the form by your own, Then in code behind ask for that value in the Page_Load, and if the value is set you execute your function... ...As you can see it is a very dirty solution but the Hyperlink control and the ones you can make in html through the format menu don´t have events associated and they don´t do postbacks to the server when clicked...so other approaches should be similars to this one... if someone has a cleaner way, please post it. My suggestion : use the LinkButton control and you'll only need a single line of code in which you´ll call your function.

              R Offline
              R Offline
              R Thomas 0
              wrote on last edited by
              #6

              can u tell me how i can do it if i use linkbutton??? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

              K 1 Reply Last reply
              0
              • M Mazdak

                You can do it easily Josesh, I don't rememeber the exact syntax now but its something like this: [/> Maybe others correct this or you can find correct syntax with googling.](<%#functionnameincodebehind()%)

                R Offline
                R Offline
                R Thomas 0
                wrote on last edited by
                #7

                i tried it..... doesn't work... :( "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

                M 1 Reply Last reply
                0
                • R R Thomas 0

                  i tried it..... doesn't work... :( "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

                  M Offline
                  M Offline
                  Mazdak
                  wrote on last edited by
                  #8

                  Joseph R. Thomas wrote: doesn't work... I told you that its not the exact one , you can find exact solution with seaching or waiting for someone else or me to go home ans see the correct solution,but don't worry its not hard one. Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

                  R 1 Reply Last reply
                  0
                  • M Mazdak

                    Joseph R. Thomas wrote: doesn't work... I told you that its not the exact one , you can find exact solution with seaching or waiting for someone else or me to go home ans see the correct solution,but don't worry its not hard one. Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

                    R Offline
                    R Offline
                    R Thomas 0
                    wrote on last edited by
                    #9

                    tks a lot....but if i search for wat keyword should i search for?? i mean what is this thing called?? linking?? or something??:confused: tks a lot... :) "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

                    1 Reply Last reply
                    0
                    • R R Thomas 0

                      can u tell me how i can do it if i use linkbutton??? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

                      K Offline
                      K Offline
                      killerslaytanic
                      wrote on last edited by
                      #10

                      Well... as you seem to like throwing a lot of code here we go : LOL In this page i´ve put a Hyperlink control if the link you desire is one of those you get via the Format menu after selecting the text the only thing you have to change is to assign its href property to the same value the link i give you has in its NavigateUrl property.... Also I´ve put a hidden field and have set its runat=server... And the function myfunc which sets the value of the hidden field and does the submit..Notice it is called in the NavigateURL property (which will be the href attribute when the page is rendered) in summary what you have to do. 1.Put your hyperlink 2.put a hidden field (named Hid in the example)and set it to Run at server (runat="server") 2.Write a function similar to the one called "myfunc" i wrote in the aspx code (basically you won´t need to change it) 3 Set your hyperlink's NavigateURL="javascript:myfunc();" That´s all in the aspx page Now in codebehind 1. In Page_load check the value of the hidden field 2.If it is ="1" call your function 3. Reset the Hidden field value to "0" otherwise your function will be executed when any control (not just the hyperlink) produces a postback after the first time the hyperlink is pressed The aspx code follows: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="WebTests.WebForm1"%> WebForm1 function myfunc() { document.Form1.Hid.value="1"; Form1.submit(); } HyperLink Label Then in the server side (i gave you a .vb file, in .cs is the same thing with the proper sintax) The server function i provided just adds an A character to t

                      1 Reply Last reply
                      0
                      • M Mazdak

                        You can do it easily Josesh, I don't rememeber the exact syntax now but its something like this: [/> Maybe others correct this or you can find correct syntax with googling.](<%#functionnameincodebehind()%)

                        K Offline
                        K Offline
                        killerslaytanic
                        wrote on last edited by
                        #11

                        I´m afraid it´s not possible since: 1. The hyperlinks controls (not the LinkButton) don´t do postback when clicked 2. Regardless of that, You are attempting to call a server function from the client side Anyway I searched a little and there's nothing similar to the function you suggested. If you know it is possible in a way similar to that one you propossed(i really doubt it) could you put the right way here please? Regards

                        M 1 Reply Last reply
                        0
                        • K killerslaytanic

                          I´m afraid it´s not possible since: 1. The hyperlinks controls (not the LinkButton) don´t do postback when clicked 2. Regardless of that, You are attempting to call a server function from the client side Anyway I searched a little and there's nothing similar to the function you suggested. If you know it is possible in a way similar to that one you propossed(i really doubt it) could you put the right way here please? Regards

                          M Offline
                          M Offline
                          Mazdak
                          wrote on last edited by
                          #12

                          You are right, that doesn't work for hyperlink as much as search again. Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope

                          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