Normally the way you would do this is to have you javascript modify an input control so that the value will be posted back with the Button
click. If you want the user to visually not be able see the data that your javascript is modifying to post back then you can write it to a HiddenField
.
You can use the OnClientClick
to setup the javascript to run before the postback happens to ensure your modified value is put into the input control. Eg:
<asp:Button ID="yourButton" runat="server" Text="Click Me!"
OnClientClick="YourFunctionToAddStringToControl(); return true;"
OnClick="yourButton_Click" />
So you just need to swap the call to YourFunctionToAddStringToControl
with your modified javascript function that is writing the value to a HiddenField
or another input control. Then update your server side click handler to access the field.
Side Note: When using javascript to write to server side controls such as HiddenField
, don't forget to use <%= yourHiddenField.ClientID %>
to get the correct control name.