punter
punter

Reputation: 460

dynamic query string in jquery

I have a datalist for list of documents enter image description here

 <asp:DataList ID="DLDossierList" runat="server" >

            <ItemTemplate>

                <div class="doss_hea_seno_2" url="dossier_timeline.aspx">
                   .
                   .
        <asp:HiddenField ID="hfDocNo" runat="server" Value='<%#("DoCNo") %>' />

                   .
                </div>

            </ItemTemplate>
        </asp:DataList>

I want to redirect to another page when he clicks on (div) list item i.e document name . for this I am using following script :

<script>
            $(document).ready(function () {
                $('.doss_hea_seno_2').click(function () {
                    window.parent.location = $(this).attr("url");
                    return false;

                });

            });
</script>

but now I want to pass hidden field value as a query string . how can i achieve this ?

Upvotes: 0

Views: 449

Answers (2)

tenbits
tenbits

Reputation: 8008

As I remember, WebForms creates ids for elements like Somthing_DLDossierList_hfDocNo

Then you can look for the hidden input field like this:

$('[id$="hfDocNo"]').val() // -> value of the field

jquery doc

Upvotes: 0

Ricky Stam
Ricky Stam

Reputation: 2126

You can have the custom query string as data attribute (data-querystring) and do something similar to the following:

You can add the data attribute on DataBound from code behind

<script>
         $(document).ready(function () {
             $('.doss_hea_seno_2').click(function () {
                 window.parent.location = $(this).attr("url") + "?customqs=" + $(this).data("querystring");
                 return false;
              });
           });
</script>

Upvotes: 1

Related Questions