Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set up a JQuery selector for a HtmlInputHidden-field in a server control
    primarykey
    data
    text
    <p>I am creating a server control called DateTimePicker. In this I have a property that get/sets the time format. I've tried to store the time format in a hidden input field.</p> <pre><code>public class DateTimePicker : WebControl, INamingContainer { private TextBox _dateTextBox; private TextBox _timeTextBox; private HtmlInputHidden _timeFormat; ... public string TimeFormat { get { string timeFormat = _timeFormat.Value; if(string.IsNullOrEmpty(timeFormat)) { timeFormat = DEFAULT_TIME_FORMAT; } return timeFormat; } set { _timeFormat.Value = value; } } ... protected override void CreateChildControls() { Controls.Clear(); _dateTextBox = new TextBox(); _dateTextBox.ID = "DateTextBox"; _dateTextBox.CssClass = "DatePickerInput"; _timeTextBox = new TextBox(); _timeTextBox.ID = "TimeTextBox"; _timeTextBox.CssClass = "TimePickerInput"; _timeTextBox.Width = Unit.Pixel(70); _timeFormat = new HtmlInputHidden(); _timeFormat.ID = "TimeFormatInput"; Controls.Add(_dateTextBox); Controls.Add(_timeTextBox); Controls.Add(_timeFormat); } ... </code></pre> <p>The textbox holding the time is extended with a JQuery time picker like this:</p> <pre><code>$('.TimePickerInput').timePicker({ step: 60, timeFormat: GetTimeFormat() }); function GetTimeFormat() { var timeFormat = $('#TimeFormatInput').val(); //This does not work return timeFormat; //return 'hh:mm:ss tt'; //This works }; </code></pre> <p>The setter and getter for the server control works, but in the selector for the HtmlInputHidden-field does not work. How can I set up this selector correctly?</p> <p>Edit (Here is the generated html): </p> <pre><code>&lt;div&gt; &lt;input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCgLwj7S1AQLalbH6BQKys6HCBwLLy8GzCQKVnffiAgKC8LSoDgKTgNnOAQKM54rGBgK5ttWBDwLR0LuADBg3bjYl8jVMd+TqBkYL8mvSQmAH" /&gt; &lt;/div&gt; &lt;div&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1')); Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], [], [], 90); //]]&gt; &lt;/script&gt; &lt;div id="UpdatePanel1"&gt; &lt;span id="LoadTimer" style="visibility:hidden;display:none;"&gt;&lt;/span&gt; &lt;span id="FromDateTime"&gt;&lt;input name="FromDateTime$DateTextBox" type="text" id="FromDateTime_DateTextBox" class="DatePickerInput" /&gt;&lt;input name="FromDateTime$TimeTextBox" type="text" id="FromDateTime_TimeTextBox" class="TimePickerInput" style="width:70px;" /&gt;&lt;input name="FromDateTime$TimeFormatInput" type="hidden" id="FromDateTime_TimeFormatInput" /&gt;&lt;/span&gt; &lt;br /&gt; &lt;br /&gt; &lt;span id="ToDateTime"&gt;&lt;input name="ToDateTime$DateTextBox" type="text" id="ToDateTime_DateTextBox" class="DatePickerInput" /&gt;&lt;input name="ToDateTime$TimeTextBox" type="text" id="ToDateTime_TimeTextBox" class="TimePickerInput" style="width:70px;" /&gt;&lt;input name="ToDateTime$TimeFormatInput" type="hidden" id="ToDateTime_TimeFormatInput" /&gt;&lt;/span&gt; &lt;br /&gt; &lt;br /&gt; &lt;input type="submit" name="Button1" value="Postback" id="Button1" /&gt; &lt;br /&gt; &lt;br /&gt; &lt;input type="submit" name="GetDateTimeButton" value="Get Selected DateTime" id="GetDateTimeButton" /&gt; &lt;input name="SelectedDateTimeTextBox" type="text" id="SelectedDateTimeTextBox" /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>After looking at the source, I've tested using var timeFormat = $('#FromDateTime_TimeFormatInput').val(); This works, but the 'FromDateTime_'-part is added from the id used for the server control. I have to get a way to get it without knowing that. If it is more than one 'TimeFormatInput'-fields on the page, it does not matter which one i'll read, the will have the same content.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload