我遇到了一个问题,我的代码调用了一个模态,当模态加载时,它应该填充模态中的控件,并将值发送到javascript中。除了所有控件都为空之外,它加载没有错误。我是ajax和javascript的新手,所以它可能很简单,我很遗憾。
感谢。
这是我的Javascript:
function RowClickedResults(sender, eventArgs) {
sender.get_masterTableView().fireCommand("View", eventArgs._itemIndexHierarchical);
}
function createEditAccount(ReceivedDate, DepositedDate, tbCompanyName, tbCheckAmount, tbCheckNum, tbDesc, cbResultsBreak, cbResultAcctNum, tbResultBreak, tbResultNotes) {
$("#EditAccount").modal('show');
$('#EditAccount').on('load', function () {
var rDate = $telerik.findControl(document, "rdResultReceiveDate");
var dDate = $telerik.findControl(document, "rdResultDepositDate");
var Comp = $telerik.findControl(document, "tbResultCompany");
var CheckAmt = $telerik.findControl(document, "tbResultCheckAmt");
var CheckNum = $telerik.findControl(document, "tbResultCheckNum");
var Desc = $telerik.findControl(document, "tbResultsDesc");
var Break = $telerik.findControl(document, "cbResultsBreak");
var AcctNum = $telerik.findControl(document, "cbResultAcctNum");
var BreakAmt = $telerik.findControl(document, "tbResultBreak");
var Notes = $telerik.findControl(document, "tbResultNotes");
rDate.set_selectedDate = ReceivedDate;
dDate.set_selectedDate = DepositedDate;
Comp.text = tbCompanyName;
CheckAmt.text = tbCheckAmount;
CheckNum.text = tbCheckNum;
Desc.text = tbDesc;
AcctNum.value = cbResultAcctNum;
BreakAmt.text = tbResultBreak;
Notes.text = tbResultNotes;
});
}
这是我的模态:
<div id="EditAccount" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div class="row">
<div class="col-xs-10">
<h4>Edit Account Receivable</h4>
</div>
</div>
<div class="modal-body">
<div class="row text-center">
<div>
<div class="col-cx-7 text-center">
<div style="padding: 5px;">
<asp:Label runat="server" Text="Received Date: " />
<telerik:RadDatePicker runat="server" ID="rdResultReceiveDate" Culture="en-US" />
</div>
<div style="padding: 5px;">
<asp:Label runat="server" Text="Deposited Date: " />
<telerik:RadDatePicker runat="server" ID="rdResultDepositDate" Culture="en-US" />
</div>
<div style="padding: 5px;">
<asp:Label runat="server" Text="Company: " />
<asp:TextBox runat="server" ID="tbResultCompany" />
</div>
<div style="padding: 5px;">
<asp:Label runat="server" ID="lblResultCheck" Text="Check Amount: " />
<asp:TextBox runat="server" ID="tbResultCheckAmt" />
</div>
<div style="padding: 5px;">
<asp:Label runat="server" Text="Check Number: " />
<asp:TextBox runat="server" ID="tbResultCheckNum" />
</div>
<div style="padding: 5px;">
<asp:Label runat="server" Text="Description: " />
<asp:TextBox runat="server" ID="tbResultsDesc" />
</div>
</div>
<div class="col-cx-7 text-center">
<div style="padding: 5px;">
<asp:Label runat="server" Text="Break Down: " />
<telerik:RadComboBox runat="server" RenderMode="Lightweight" ID="cbResultsBreak" AutoPostBack="false"
AppendDataBoundItems="true" CloseDropDownOnBlur="true" DropDownAutoWidth="Enabled"
ShowDropDownOnTextboxClick="true" Enabled="true" OnSelectedIndexChanged="BreakDownSelectedIndexChanged">
</telerik:RadComboBox>
</div>
<div style="padding: 5px;">
<asp:Label runat="server" Text="Account Number: " />
<telerik:RadComboBox runat="server" RenderMode="Lightweight" ID="cbResultAcctNum" AutoPostBack="false"
AppendDataBoundItems="true" CloseDropDownOnBlur="true" DropDownAutoWidth="Enabled"
ShowDropDownOnTextboxClick="true" Enabled="true">
</telerik:RadComboBox>
</div>
<div style="padding: 5px;">
<asp:Label runat="server" Text="Break Down: " />
<asp:TextBox runat="server" ID="tbResultBreak" />
</div>
<div style="padding: 5px;">
<asp:Label runat="server" Text="Notes(Optional): " />
<asp:TextBox runat="server" ID="tbResultNotes" />
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-xs-6 text-right">
<asp:LinkButton runat="server" ID="btnEditSave" CssClass="btn btn-success" OnClientClick="saveEditAccount(this); return false;" OnClick="btnSaveEdit_Click">Save</asp:LinkButton>
</div>
<div class="col-xs-6 text-left">
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</div>
</div>
<telerik:RadWindowManager RenderMode="Lightweight" ID="RadWindowManager2" runat="server" />
</div>
这是我调用javascript的地方:
<telerik:RadGrid ID="rgResults" runat="server" FooterStyle-ForeColor="#BA1A8B"
HeaderStyle-BackColor="#39ac99"
HeaderStyle-Font-Bold="true" AlternatingRowStyle-BackColor="White"
AllowPaging="true" PageSize="10"
OnItemCommand="rgResults_ItemCommand"
OnNeedDataSource="rgResults_NeedDataSource"
OnItemDataBound="rgResults_ItemDataBound"
OnPreRender="rgResults_PreRender"
AutoGenerateColumns="false">
<ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="false">
<Selecting AllowRowSelect="true"></Selecting>
<ClientEvents OnRowClick="RowClickedResults" />
</ClientSettings>
<MasterTableView DataKeyNames="Deposited_Date">
<Columns>
<telerik:GridTemplateColumn UniqueName="commandColumn">
<ItemTemplate>
<telerik:RadImageButton ID="btnDelete" runat="server" CommandName="Delete" ImageUrl="~/Content/Images/delete.gif" />
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn HeaderText="Deposit Date" DataField="Deposited_Date" UniqueName="Deposited_Date" />
<telerik:GridBoundColumn HeaderText="Company Name" DataField="Company_Name" UniqueName="Company_Name" />
</Columns>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
</telerik:RadGrid>
这是我背后的代码:
case "View":
{
foreach (GridDataItem item in rgResults.Items)
{
string Deposit = item.GetDataKeyValue("Deposited_Date").ToString();
ar = ydb.Accounts_Receivable.ToList().Where(t => t.Deposited_Date == DateTime.Parse(Deposit)).ToList();
foreach (Accounts_Receivable ar2 in ar.ToList())
{
if (SearchByDate.SelectedDate.Value.ToString() == Deposit)
{
if (ar2.Posted_Date == null)
{
Accounts_Receivable_Breakdown arb = ar2.Accounts_Receivable_Breakdown.ToList().Where(t => t.Accounts_Receivable_ID == ar2.Accounts_Receivable_ID).First();
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "createEditAccount(\"" + ar2.Received_Date.Value.ToString() + "\",\"" + ar2.Deposited_Date.ToString() + "\",\"" +
ar2.Company_Name + "\",\"" + ar2.Check_Amount + "\",\"" + ar2.Check_Number + "\",\"" +
ar2.Description_ + "\",\"" + arb.Breakdown_Amount +
"\",\"" + arb.Account_Number + "\",\"" + arb.Breakdown_Amount + "\",\"" + arb.Notes + "\");", true);
}
else
{
rdResultReceiveDate.Enabled = false;
rdResultReceiveDate.Enabled = false;
tbResultCompany.ReadOnly = true;
tbResultCheckAmt.ReadOnly = true;
tbResultCheckNum.ReadOnly = true;
tbResultsDesc.ReadOnly = true;
cbResultAcctNum.Enabled = false;
Accounts_Receivable_Breakdown arb = ar2.Accounts_Receivable_Breakdown.ToList().Where(t => t.Accounts_Receivable_ID == ar2.Accounts_Receivable_ID).First();
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "createEditAccount(\"" + Eval("ar2.Received_Date.Value").ToString() + "\",\"" + Eval("ar2.Deposited_Date").ToString() + "\",\"" +
Eval("ar2.Company_Name") + "\",\"" + Eval("ar2.Check_Amount") + "\",\"" + Eval("ar2.Check_Number") + "\",\"" +
Eval("ar2.Description_") + "\",\"" + Eval("arb.Breakdown_Amount") +
"\",\"" + Eval("arb.Account_Number") + "\",\"" + Eval("arb.Breakdown_Amount") + "\",\"" + Eval("arb.Notes") + "\");", true);
}
}
}
}
break;
}
答案 0 :(得分:0)
找出问题所在。代码必须做回发,因为我触摸了服务器端代码,而模式是在我的updatepanel内部。将模式移出更新面板,让代码完成回发,然后再尝试查找控件并将数据设置为它们。