Call server site function into the javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankajprakash
    New Member
    • Feb 2007
    • 70

    Call server site function into the javascript

    Hi all,
    I am creating a table at the runtime, which contains 4 rows and every rows contains 3 textboxes and a dropdownlist box. First when the page is loaded the table creates the 4 rows. I have also used a Linkbutton for adding more row. I want when I click that link button page should not be post back and add a new row. but when i click on the linkbutton it postbacks the page and the table again created and all the data in the textboxes are lost. So please tell me what should i do and i Linkbutton is medatory. We can also use <a> instead of linkbutton.

    I have created a function for adding a new row in the table, and want to call that function in a javascript function and that javascript function should be called on the OnClientClick() event of linkbutton.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by pankajprakash
    Hi all,
    I am creating a table at the runtime, which contains 4 rows and every rows contains 3 textboxes and a dropdownlist box. First when the page is loaded the table creates the 4 rows. I have also used a Linkbutton for adding more row. I want when I click that link button page should not be post back and add a new row. but when i click on the linkbutton it postbacks the page and the table again created and all the data in the textboxes are lost. So please tell me what should i do and i Linkbutton is medatory. We can also use <a> instead of linkbutton.

    I have created a function for adding a new row in the table, and want to call that function in a javascript function and that javascript function should be called on the OnClientClick() event of linkbutton.

    LinkButtons are converted into <a href> tags when rendered in the browser.

    Why are you having a problem adding the OnClientClick to the link button...

    Here's an example of how to do it (through asp):
    [code=asp]
    <asp:LinkButt on ID="Lbtn_MyLink Button" runat="server" OnClientClick=" myJavaScriptFun ctionCall(); return false;" > </asp:LinkButton>[/code]

    You're going to need the "return false" in there to prevent the postback.

    -Frinny

    Comment

    • pankajprakash
      New Member
      • Feb 2007
      • 70

      #3
      ok, it's fine. I will call the myJavaScriptFun ctionCall() on Client click but how can i call the that server site function which add the new row in the table.

      Originally posted by Frinavale
      LinkButtons are converted into <a href> tags when rendered in the browser.

      Why are you having a problem adding the OnClientClick to the link button...

      Here's an example of how to do it (through asp):
      [code=asp]
      <asp:LinkButt on ID="Lbtn_MyLink Button" runat="server" OnClientClick=" myJavaScriptFun ctionCall(); return false;" > </asp:LinkButton>[/code]

      You're going to need the "return false" in there to prevent the postback.

      -Frinny

      Comment

      • rsdev
        New Member
        • Jul 2007
        • 149

        #4
        Originally posted by pankajprakash
        ok, it's fine. I will call the myJavaScriptFun ctionCall() on Client click but how can i call the that server site function which add the new row in the table.
        To call the serve side function you need to post back to the server. You could do a partial post back using AJAX. Is this an option?

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by pankajprakash
          ok, it's fine. I will call the myJavaScriptFun ctionCall() on Client click but how can i call the that server site function which add the new row in the table.

          You can't call a function on the server without a Postback...sorr y.
          But Rsdev has made a valid point....you could use Ajax to make an asynchronous call to the server's function.

          Microsoft's put out ASP.NET Ajax...which is basically a framework that helps to implement Ajax into your ASP.NET project.
          It's really helpful as it reduces a lot of coding that would have had to have been done by hand otherwise.

          Check it out (you'll be interested in the Update Panel and set it's UpdateMode to Condition)

          Cheers!
          -Frinny

          Comment

          Working...