By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,297 Members | 701 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,297 IT Pros & Developers. It's quick & easy.

How can call function using button?

P: 53
The following lines of code calling TerminateManager.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.

Expand|Select|Wrap|Line Numbers
  1. this.PlaceHolderTerminateManagerButton.Controls.Ad d(new LiteralControl("<input type='Button' value='Terminate Manager' onclick='javascript:location.href=\"TerminateManag er.aspx?orgID="+ orgID + "\";'"));
Mar 8 '10 #1

✓ answered by Bassem

Hey,

For the C# Method, use this:
1. The page that send the request:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1.     protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         string param = Request.QueryString["myParam"];
  4.         if("x" == param)
  5.             MyMethod();
  6.     }
  7.  
I hope that will help!

Thanks,
Bassem

Share this Question
Share on Google+
4 Replies

100+
P: 344
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:
Expand|Select|Wrap|Line Numbers
  1. ?orgID="+ orgID 
Then in your Page_Load Method, or onload function check these parameters and invoke the Method or call the Function.

Thanks,
Bassem
Mar 8 '10 #2

100+
P: 344
Hey,

For the C# Method, use this:
1. The page that send the request:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1.     protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         string param = Request.QueryString["myParam"];
  4.         if("x" == param)
  5.             MyMethod();
  6.     }
  7.  
I hope that will help!

Thanks,
Bassem
Mar 8 '10 #3

P: 53
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!
Mar 9 '10 #4

100+
P: 344
Hi,

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

Thanks,
Bassem
Mar 11 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.