我正在构建一个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中