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. stop postback in asp.net

stop postback in asp.net

Scheduled Pinned Locked Moved Web Development
csharpjavascripthtmlasp-netsysadmin
5 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.
  • C Offline
    C Offline
    cmarmr
    wrote on last edited by
    #1

    how do i use my javascript to stop postback in the input is not correct i don't want it to post back to the server here is the code: private void Page_Load(object sender, System.EventArgs e) { // Form the script that is to be registered at client side. String scriptString = " \n"; scriptString += "function DoClick()\n {\n"; scriptString += "\t myForm.show.value='Welcome to Microsoft .NET'; \n "; scriptString += "return true;\n}"; scriptString += ""; if(!this.IsClientScriptBlockRegistered("clientScript")) this.RegisterClientScriptBlock("clientScript", scriptString); button.Attributes["onclick"]="DoClick()"; } here is the html:

    Thanks chad -- modified at 22:40 Monday 27th February, 2006

    G H 2 Replies Last reply
    0
    • C cmarmr

      how do i use my javascript to stop postback in the input is not correct i don't want it to post back to the server here is the code: private void Page_Load(object sender, System.EventArgs e) { // Form the script that is to be registered at client side. String scriptString = " \n"; scriptString += "function DoClick()\n {\n"; scriptString += "\t myForm.show.value='Welcome to Microsoft .NET'; \n "; scriptString += "return true;\n}"; scriptString += ""; if(!this.IsClientScriptBlockRegistered("clientScript")) this.RegisterClientScriptBlock("clientScript", scriptString); button.Attributes["onclick"]="DoClick()"; } here is the html:

      Thanks chad -- modified at 22:40 Monday 27th February, 2006

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      If the input is not correct, return false from the javascript function. --- b { font-weight: normal; }

      C 1 Reply Last reply
      0
      • G Guffa

        If the input is not correct, return false from the javascript function. --- b { font-weight: normal; }

        C Offline
        C Offline
        cmarmr
        wrote on last edited by
        #3

        i returned false and a postback stilled happeded i have server side code on this asp.net button which writes "server" in that textbox and i want to be able to stop that from happening thanks chad

        G 1 Reply Last reply
        0
        • C cmarmr

          i returned false and a postback stilled happeded i have server side code on this asp.net button which writes "server" in that textbox and i want to be able to stop that from happening thanks chad

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Right. You have to return the value in the event also: button.Attributes["onclick"] = "return DoClick()"; --- b { font-weight: normal; }

          1 Reply Last reply
          0
          • C cmarmr

            how do i use my javascript to stop postback in the input is not correct i don't want it to post back to the server here is the code: private void Page_Load(object sender, System.EventArgs e) { // Form the script that is to be registered at client side. String scriptString = " \n"; scriptString += "function DoClick()\n {\n"; scriptString += "\t myForm.show.value='Welcome to Microsoft .NET'; \n "; scriptString += "return true;\n}"; scriptString += ""; if(!this.IsClientScriptBlockRegistered("clientScript")) this.RegisterClientScriptBlock("clientScript", scriptString); button.Attributes["onclick"]="DoClick()"; } here is the html:

            Thanks chad -- modified at 22:40 Monday 27th February, 2006

            H Offline
            H Offline
            HimaBindu Vejella
            wrote on last edited by
            #5

            Use if(!Page.IsPostBack) button.Attributes["onclick"]="DoClick()"; Senior Software Engineer

            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