0

我正在尝试从“DisplayBrandGridView_RowInserting”事件背后的代码提交一个 JS 函数。当 RegisterStratupScipt 运行时,什么也没有发生,甚至没有命中 JS 函数。

将记录插入数据库后(在此事件中成功),我需要立即执行 JS 函数,该函数将显示一个按钮以将数据添加到另一个表。请注意,当从客户端执行时,此 JS 函数可以正常工作。我不在乎它是从客户端还是服务器执行的。我能想到在这些条件下执行它的唯一方法是从服务器端。

这是从 HTML 中启动新行对话框的事件:

    <dx:ASPxButton ID="btnAddNew" Text="Add New" runat="server" CausesValidation="false" AutoPostBack="false" Theme="PlasticBlue" ClientInstanceName="btnAddNew">
 <ClientSideEvents Click="function (s,e) { DisplayBrandsClientGridView.AddNewRow(); }" />
 </dx:ASPxButton>

这是JS函数:

function ShowBrandModelSearch()
 {
 var associateBrand = eval( '<%# BrandModelSearch.ClientInstanceName %>' );
 associateBrand.DoClick();
 }

这是从上面的 HTML 客户端事件执行的代码:

protected void DisplayBrandGridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
 {
 var grid = sender as ASPxGridView;

 try
 {
 grid.JSProperties["cpDesc"] = false;

 var description = e.NewValues["Description"].ToString().Trim();

 using (var dcWeb = DataContextExtension.FromConfig<DCMerchant>())
 {
 if (dcWeb.Merch_DisplayBrands.Any(a => a.Description == description))
 {
 // Display Brand already exists
 grid.JSProperties["cpDesc"] = true;
 grid.JSProperties["cpConfirmationMessageHeader"] = "Display Brand Exists";
 grid.JSProperties["cpConfirmationMessage"] = string.Format("Display Brand {0} already exists. Please specify a unique name.", description);
 }
 else
 {
 try
 {
 var dBrand = new Merch_DisplayBrand()
 {
 Description = description,
 IsActive = Utility.GetValue<bool>(e.NewValues["IsActive"]),
 ModifiedBy = CurrentUser.LawsonId,
 ModifiedOn = DateTime.Now
 };
 dcWeb.Merch_DisplayBrands.InsertOnSubmit(dBrand);
 dcWeb.SubmitChanges(ConflictMode.ContinueOnConflict);

 // Needed to keep track of filter
 if (string.IsNullOrWhiteSpace(Utility.GetValue<string>(PageData["FilterText"])))
 {
 grid.JSProperties["cpFilterText"] = description;
 PageData["FilterText"] = description;
 SearchTextASPxTextBox.Text = description;
 }
 else
 grid.JSProperties["cpFilterText"] = PageData["FilterText"];

 Page.ClientScript.RegisterStartupScript(this.GetType(), "BrandModelSearch", "ShowBrandModelSearch();", true);

 }
 catch (Exception ex)
 {
 if (!ex.ResolveConflicts(dcWeb))
 {
 ex.AddTruncatedFieldInfo(dcWeb);
 throw;
 }
 }
 }
 }
 }
 catch (Exception ex)
 {
 ex.Log();
 }
 finally
 {
 e.Cancel = true;
 grid.CancelEdit();
 }
 }

添加一行并且“添加新对话框”消失后,如何成功执行此功能(客户端或服务器端)?

4

2 回答 2

3

您需要在EndCallback处理程序中执行您的 js 代码。我在这里这里回答了类似的问题。

于 2013-11-04T08:09:15.617 回答
0

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "BrandModelSearch", ShowBrandModelSearch(), false);

于 2013-11-03T03:29:09.450 回答