Add control at runtime, how to get values with jQuery
My Webforms are shaky, so excuse me if not clear.
I build up a table of dates and the different hours a user worked each day (at runtime since one don't know the start / end date before).
So one column per date , and a row cell for the things like the number of "scheduled hours", "actual hours" etc for each day.
In the last row cell I load a user control that I use to let the user indicate if they accept, and if not, enter a reason (via jquery ui dialog).
UserControl (the span's are just a technique I got here for creating iPhone like toggle buttons):
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DisputeControl.ascx.cs" Inherits="DotNetNuke.Modules.Fusion.TimeSheets.Controls.DisputeControl" %>
<p class="field switch">
<asp:label runat="server" ID="disputeReason"></asp:label>
<br />
<label class="cb-enable selected"><span>Y</span></label>
<label class="cb-disable"><span>N</span></label>
<input type="checkbox" id="checkbox" class="checkbox" />
<asp:HiddenField runat="server" ID="workDateId" />
</p>
the idea is that when the user enter a dispute to store it in a hidden control until I save the form (remember there will be one for each day). At present I just try to use a label, so I got something visual while developing.
If I put the following script alon with the control, the dialog become unresponsive after opening (will not close), so it's in my page file:
Code:
<script type="text/javascript">
$(document).ready(function () {
$(".cb-enable").click(function () {
var parent = $(this).parents('.switch');
$('.cb-disable', parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox', parent).attr('checked', true);
var date = "how to get that workdateid?";
ClearDisputeReason(date);
});
$(".cb-disable").click(function () {
var parent = $(this).parents('.switch');
$('.cb-enable', parent).removeClass('selected');
$(this).addClass('selected');
$('.checkbox', parent).attr('checked', false);
var date = "how to get that workdateid?";
GetDisputeReason(date);
});
function ClearDisputeReason(date) {
alert("Clear dispute reason for " + date);
};
function GetDisputeReason(date) {
var win = $('<div><p>Enter your reason for dispute:</p></div>');
var userInput = $('<textarea style="width:100%;height:200px;"></textarea>');
userInput.appendTo(win);
$(win).dialog({
'modal': true,
'buttons': {
'Ok': function () {
$(this).dialog('close');
var reason = $(userInput).val();
alert(reason + " for " + date);
},
'Cancel': function () {
$(this).dialog('close');
return '';
}
}
});
};
});
</script>
For now, I just want to try get hold of the label for the correct control instance, when the user entered text in the dialog and clicked ok.
I moved the script to the control itself, since I cannot do something like var id = $("#<%=workDateId.ClientID %>"); outside o the control.
But then the close functionality of the dialog go all cookoo and whatever code I wrtie to run (javascript) get run for each of my control iinstances.
perhaps I'm just having something small wrong, or perhaps I took the whole wrong approach?