我正在构建一个 GridView 派生控件,该控件具有编辑按钮,可以打开一个新的 url 进行编辑或为编辑 url 打开一个模式窗口(通过 jquery 对话框)。问题是打开模态窗口的javascript没有触发(可能是它触发了,但由于回发我看不到它,但是没有出现console.log,所以我认为没有触发)。
javascript代码是正确的,如果我将它粘贴到控制台中,它会达到预期的效果。
所以这是我在 Sub 中的代码:
Protected Shadows Sub RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles MyBase.RowCommand
If e.CommandName = "EditInForm" Then
If Not FormularioModal Then
HttpContext.Current.Response.Redirect(url_edicion, True)
Else
'Must open a modal windows, registers JS to open dialog
Dim scriptModal As String = scriptAbreModal(url_edicion) 'This function creates correct javascript
log.log(String.Format("Registering {0}", scriptModal))
Dim page As Page = HttpContext.Current.Handler
Dim nombreScript As String = "scrAbreModal" & Guid.NewGuid().ToString().GetHashCode().ToString("x")
Dim cstype As System.Type = page.GetType
Dim cs As ClientScriptManager = page.ClientScript
If (Not cs.IsClientScriptBlockRegistered(cstype, nombreScript)) Then
cs.RegisterStartupScript(page.GetType, nombreScript, scriptModal)
End If
End If
End If
(也尝试过RegisterClientScriptBlock
代替RegisterStartupScript
)
只是为了记录,生成的javascript代码是:
<script type="text/javascript">
var miVentanaModal;
miVentanaModal = $('<iframe id="iGridViewModalIFrame" src="q_pregunta_elementodoc.aspx?op=upd&id=28&pregunta=6&modal=true" />')
.dialog({ title: 'Title',
autoOpen: true,
width: 575,
height: 320,
modal: true,
resizable: true,
autoResize: true,
overlay: { opacity: 0.5, background: "black" } }).width(555).height(300);
</script>
有任何想法吗?
谢谢
PS:此代码在纯代码类中,它在包含一些控件和实用程序的 dll 中