Mohsen
Mohsen

Reputation: 4266

How to set text of asp.net server control in client side via its id?

I have tree textbox inputs in client side and tree aspxtextboxes in server side i want to set text of each server textbox to related client input in client side as client side values changed but i want to do all in a single method to do it in separate methods i can use controlName.SetText("text"); but i want something like this:

    $(document).ready(function () {
            $("input").change(function () {
                //                var servercontrol = document.getElementById((this.name).substring(6));
               //or $("#" + (this.name).substring(6)).SetText("some text");
                servercontrol.SetText(this.value);

            });

which makes error. Thanks in advanced.

Edit: I have to retrieve sender name at client side

Upvotes: 0

Views: 1268

Answers (1)

VinayC
VinayC

Reputation: 49215

If your script is in aspx file then you can use server side directive to get client id - for example:

$('#<%= MyTextBox.ClientID %>').val("Set this text");

Otherwise, you have to somehow pass the control's client id to the relevant script.

Upvotes: 1

Related Questions