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. Add javascript Function in MenuItem Click event

Add javascript Function in MenuItem Click event

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netdatabase
5 Posts 4 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.
  • A Offline
    A Offline
    Abdul Rahman Hamidy
    wrote on last edited by
    #1

    Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.

    Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

    N S M 3 Replies Last reply
    0
    • A Abdul Rahman Hamidy

      Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.

      Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You don't need to implement it in C#, add an onclientclick to the menu item markup or do it from javaScript


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • A Abdul Rahman Hamidy

        Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.

        Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

        S Offline
        S Offline
        Sandeep Mewara
        wrote on last edited by
        #3

        You can do this on server side, codebehind cs file:

        foreach (MenuItem item in myMenu.Items)
        {
        item.NavigateUrl = "javascript:CallaMethodOfJavascript();";
        }

        A 1 Reply Last reply
        0
        • S Sandeep Mewara

          You can do this on server side, codebehind cs file:

          foreach (MenuItem item in myMenu.Items)
          {
          item.NavigateUrl = "javascript:CallaMethodOfJavascript();";
          }

          A Offline
          A Offline
          Abdul Rahman Hamidy
          wrote on last edited by
          #4

          thx, I have used following to do it.

          using (StringWriter sw = new StringWriter())
          {
          using (HtmlTextWriter htmlWriter = new HtmlTextWriter(sw))
          {
          using (HyperLink menuLink = new HyperLink())
          {
          menuLink.NavigateUrl = item.NavigateUrl;
          menuLink.Text = item.Text;
          if (isEndNode)
          menuLink.Attributes["onclick"] = "return displayControlName('" + item.Text + "','" + item.Parent.Text + "');";
          else
          menuLink.Attributes["onclick"] = "return msgOnly();";
          menuLink.RenderControl(htmlWriter);
          item.Text = sw.ToString();
          }
          }
          }

          Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

          1 Reply Last reply
          0
          • A Abdul Rahman Hamidy

            Dear All, I am new to ASP.Net with c#. I am working in Menu control. I am trying to place a javascript function in MenuItem click event. when MenuItem are clicked certain action should be taken based on javascript function. any ideas to implement it in c#.

            Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

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

            <a href=”somepage.htm?foo=32” onClick=”functionName('val')”>foo 32</a> or <input type="button" value="123" onclick="func('123')" /> "I am trying to place a javascript function in MenuItem click event. " or do you mean OnClientClick="func();" ? <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="func();" /> http://mydevbank.com[^]

            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