How can call function using button?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deven Oza
    New Member
    • Oct 2006
    • 53

    How can call function using button?

    The following lines of code calling TerminateManage r.aspx page when I click on button(please see the code), instead of calling .aspx page I want to call function Check(), how can I do that?
    This following code is written in aspx.cs page and the function Check() I like to call is also in the same page.

    Code:
    this.PlaceHolderTerminateManagerButton.Controls.Ad d(new LiteralControl("<input type='Button' value='Terminate Manager' onclick='javascript:location.href=\"TerminateManag er.aspx?orgID="+ orgID + "\";'"));
  • Bassem
    Contributor
    • Dec 2008
    • 344

    #2
    Function?
    Is it a JavaScript function? or a C# Method?

    The only way I know for both, is what you already did, sending a parameter:
    Code:
    ?orgID="+ orgID
    Then in your Page_Load Method, or onload function check these parameters and invoke the Method or call the Function.

    Thanks,
    Bassem

    Comment

    • Bassem
      Contributor
      • Dec 2008
      • 344

      #3
      Hey,

      For the C# Method, use this:
      1. The page that send the request:
      Code:
      this.PlaceHolderTerminateManagerButton.Controls.Ad d(new LiteralControl("<input type='Button' value='Terminate Manager' onclick='javascript:location.href=\"TerminateManag er.aspx?myParam=x";'"));
      2.The page that receive the request:
      Code:
          protected void Page_Load(object sender, EventArgs e)
          {
              string param = Request.QueryString["myParam"];
              if("x" == param)
                  MyMethod();
          }
      I hope that will help!

      Thanks,
      Bassem

      Comment

      • Deven Oza
        New Member
        • Oct 2006
        • 53

        #4
        Thanks Baseem, I have created a simple button rather than using this java script and its working but I will try the way you have suggested. Thanks for your help!

        Comment

        • Bassem
          Contributor
          • Dec 2008
          • 344

          #5
          Hi,

          It wasn't a JavaScript code, it was a pure C# (Server-side code) - in case you will try it.

          Thanks,
          Bassem

          Comment

          Working...