|
-
July 14th, 2003, 06:36 AM
#1
using a client side event to fire a server side function ?
Well it has been a while since I posted last but been kinda busy. Ok,
I had something come up that I thought I would share. I had to make some menus for an internal web project that I was doing. One of the menu options needed to fire a Server Side function. I was thinking to my self "Self.. how do I do this one?"
give this a try.
This may not be the best way but it worked. Take a server control like a check box, set the AutoPostback = true.
Put a button on the same page name it something like cmdTest and hide it. Then double click on it and create a server side click event
in the event write
Respose.write("Hello World");
now take a button from the HTML controls of the tool box and put it on the page.
set it's onclick event to a client side function
onclick="test()"
When you put the checkbox on the page and set it's AutoPostBack = true a client side function is generated to handel the postback event. the function is named __doPostBack
there is a double underscore in that name so make sure that you type it correctly.
The first parameter that is passed to this function is the name of the Server control, on our case cmdTest the second value is the event to handel, the code will look something like this
<script language="JavaScript">
function test()
{
// the first parameter is the name of the control
// the second is the event to fire
__doPostBack('cmdTest','click');
}
</script>
now when you click your HTML button it will fire your server side function.
Please let me know if there are any problems with the code or if you have any questions or suggestions.
enjoy
Will
Last edited by womalley; July 14th, 2003 at 06:39 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|