views:

203

answers:

1

I have a user control that creates a jQuery DatePicker (standard one in the UI). This user control is called twice by my page (date from/to) so I have dynamic ID's for my inputs/controls/buttons/what-not. I need to somehow set either a hidden input or use a webmethod somehow to set a variable on the user control so the search function can retreive the date.

Does this make sense?

Thanks, Keith

+1  A: 

A little more clarification on your question might be helpful.

However, when you get ASP.NET and jQuery together, ASP.NET's penchant for creating complex ClientID parameters can certainly rear it's ugly head.

I've found it's useful to have a div or span with a specific class name in the user control, then have predictable markup from that point onward.

For example:

<span class="DatePickerUserControl">
    <div>...date controls</div>
    <input type="hidden" class="DatePickerHidden" ... />
</span>

Then in your jQuery:

$(".DatePickerUserControl").each(function(e) {
    $("input.DatePickerHidden", this).each(function(e) {
        // Here "this" refers to the hidden field for the particular date picker
    });
});
David
This is exactly where I went with this...except...I had to get the value in my code-behind, so I just added an asp:TextBox to the form and made it hidden. And using jQuery, I'm successfully setting the value of the textbox with the date that's selected. BUT, now I'm having trouble getting that value in my code-behind. Any suggestions?Thanks In Advance...Keith
Keith
I would recommend System.Web.UI.WebControls.HiddenField which will render an <input type="hidden" /> Not sure why you can't get the value, maybe try the hidden field and it will just work out. Otherwise, perhaps you have a problem with ViewState and your page lifecycle - the form data is processed and then afterward some code reinits the text box with a default value? There's lots of things that can cause that kind of quirky behavior.
David
I did exactly that. I used HiddenField and it worked just fine. The problem is that I didn't know what the ID of the input would be since these are being added dynamically. So, I gave each one a unique css class when they're being added and in my scripts using that same css class to select that element on the page and I'm getting the value now.
Keith