0

is it possible to get the value of the hidden field that is defined in the gridview to the javascript function so I have a gridview that has a linked button defined in it. If the user clicks on the link button, I am invoking a javascript function. I want the hidden field values in the javascript function.

also, I was wondering if it is possible to pass multiple values in one hiden field and then split them later in the javascript function.

any help will be appreciated. I don't want to go to code behind and then invoke the javascript function from there.

1

2 Answers 2

1

The first task is to determine a "suitable selector" for the hidden fields - this can be the ID (get via control.ClientID) of each individual hidden field or a more general selector like "all hidden fields in a particular div (with a particular ID)". Use <%= .. %> (or <%@ .. %> in a data-binding context) to put this information into the actual HTML response.

The exact approach will vary - basically, whichever is easiest - for the task.

Then, using your favorite library or advanced browser with applicable selector support (it is easier to find good libraries)1, use the given selector. In jQuery, this might be similar to the following, where fn is the function to process all the values. The actual selector is the stuff in quotes:

fn(jQuery("#clientIdOfGridView input[type='hidden']"))

Which might be written in ASP.NET, which is how the appropriate element ID is injected:

fn(jQuery("#<%= gridView.ClientID %> input[type='hidden']"))

These will both pass a jQuery object representing the hidden field elements to the function. Then use val() and/or each() (see the jQuery documentation and other SO questions) for usage.

There are many questions relating to just jQuery and "selecting values", so this is entire "answer" is really to provide a lead on how to get started - Happy coding :)


1 While this can be done manually with "old-school" finding a element by ID and DOM traversal, I find it a waste of my time to do such a task manually. I like jQuery but there are alternatives. Use the existing wheels; they roll relatively fast.

Sign up to request clarification or add additional context in comments.

2 Comments

I am not using jquery in my application. do you have a javascript solution.
jQuery is JavaScript (there are also lighter-weight selector libraries available; ask Mr. Google). If you prefer to do it by hand, then learn to do it by hand. That is, research that specific task, now that you know what it is. (Task: "Find hidden fields which are a descendants of a particular DOM element according to a particular structure.")
0

you can specify as much values in one value-attribute of a hidden field as you like. You must make sure use a delimiter like "," or "#" which you can use in your function to split the string of values according to your needs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.