reference a server control from within a client side script
-
Hello all, I have a couple of questions, 1- How can I reference a server control from within a client side java script block. Say if I have an
onkeypress
function on the client side for a control named "abc" and I have a control named "xyz" that is a server control. How can I reference "xyz" control from within theonkeypress
function? 2- Once I can reference the server side control "xyz", how can I force it to update, or causes a post back from within the same client side function above. Thank you all for your responses, -
Hello all, I have a couple of questions, 1- How can I reference a server control from within a client side java script block. Say if I have an
onkeypress
function on the client side for a control named "abc" and I have a control named "xyz" that is a server control. How can I reference "xyz" control from within theonkeypress
function? 2- Once I can reference the server side control "xyz", how can I force it to update, or causes a post back from within the same client side function above. Thank you all for your responses,Say, for example, your "abc" is a TextBox and "xyz" is a Button: * Create a custom control derived from TextBox (MyTextBox) * Add a property of type Button (MyTextBox.ButtonToUpdate) * Override the OnPreRender event to use Page.RegisterClientScriptBlock to register a javascript function which receives a string (the name of a button) as an argument and processes it however you want. * Override AddAttributesToRender so that it adds an attribute "onkeypress" which calls the javascript funtion using ButtonToUpdate.ClientID Now use your new control in place of the TextBox. It might sound complicated but once you've worked your way through it once, you'll find it easy to do again. Paul
-
Say, for example, your "abc" is a TextBox and "xyz" is a Button: * Create a custom control derived from TextBox (MyTextBox) * Add a property of type Button (MyTextBox.ButtonToUpdate) * Override the OnPreRender event to use Page.RegisterClientScriptBlock to register a javascript function which receives a string (the name of a button) as an argument and processes it however you want. * Override AddAttributesToRender so that it adds an attribute "onkeypress" which calls the javascript funtion using ButtonToUpdate.ClientID Now use your new control in place of the TextBox. It might sound complicated but once you've worked your way through it once, you'll find it easy to do again. Paul
Thank you for your reply