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. Adding Programmatically Buttons to an asp.net page...

Adding Programmatically Buttons to an asp.net page...

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netsysadminhelp
3 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
    Mahhouraaaaaa
    wrote on last edited by
    #1

    Hello , my problem is that i added some buttons Programmatically and i don't want them to postback the page .. just walla execute the javascriptcode how can i desactivate this property : ps: buttons are in a panel with : runat="server". foreach (Promotion promotion in promotions) { button = new Button(); button.ID = **"button"** + i; button.CssClass = "ContextMenuItem"; button.OnClientClick = **"javascript:function(this);"**; i++; button.Text = promotion.Value.ToString(); ValueListPanel.Controls.Add(button); }

    B P 2 Replies Last reply
    0
    • M Mahhouraaaaaa

      Hello , my problem is that i added some buttons Programmatically and i don't want them to postback the page .. just walla execute the javascriptcode how can i desactivate this property : ps: buttons are in a panel with : runat="server". foreach (Promotion promotion in promotions) { button = new Button(); button.ID = **"button"** + i; button.CssClass = "ContextMenuItem"; button.OnClientClick = **"javascript:function(this);"**; i++; button.Text = promotion.Value.ToString(); ValueListPanel.Controls.Add(button); }

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      Why are you not using HTML buttons?

      Cheers!! Brij

      1 Reply Last reply
      0
      • M Mahhouraaaaaa

        Hello , my problem is that i added some buttons Programmatically and i don't want them to postback the page .. just walla execute the javascriptcode how can i desactivate this property : ps: buttons are in a panel with : runat="server". foreach (Promotion promotion in promotions) { button = new Button(); button.ID = **"button"** + i; button.CssClass = "ContextMenuItem"; button.OnClientClick = **"javascript:function(this);"**; i++; button.Text = promotion.Value.ToString(); ValueListPanel.Controls.Add(button); }

        P Offline
        P Offline
        Padmanabh Ganorkar
        wrote on last edited by
        #3

        Hi, 1) If you need the asp.net button only then - Make sure your Javascript function returns false or write like this

        button.OnClientClick = "javascript:function(this); return false;";
        
        1. If you can use a HtmlButton then -

          HtmlInputButton somebuttonhtml = new HtmlInputButton();
          somehtmlbutton.ID = "somehtmlbutton";
          somehtmlbutton.Value = "ContextMenuItem";
          somehtmlbutton.Attributes.Add("onclick", "javascript:function(this);")
          ValueListPanel.Controls.Add(somehtmlbutton);

        I suggest to use HtmlButton as it satisfies your requirement and it is light weight. Hope this will help. Thanks, Padmanabh

        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