简体   繁体   中英

RegisterClientScriptBlock In userControl

This is my jquery and javascript code :

<script type="text/javascript">
$(document).ready(function () {
    //setup new person dialog
    $('#dialog').dialog({
        modal: true,
        modal: true,
        //            show: "clip",
        //          hide: "explode",
        autoOpen: false,

        title: "انتخاب فاکتور",
        open: function (type, data) {
            $(this).parent().appendTo("form");
        }
    });

    //setup edit person dialog
    $('#editPerson').dialog({
        autoOpen: false,
        draggable: true,
        title: "Edit Person",
        open: function (type, data) {
            $(this).parent().appendTo("form");
        }
    });
});

function showDialog(id) {
    $('#' + id).dialog("open");
}

function closeDialog(id) {
    $('#' + id).dialog("close");
}

The Code Is in UserControl . i can show Dialog client Side :

and i can register code from server with this code :

Page.ClientScript.RegisterClientScriptBlock(GetType(String), "script", "$(function() {showDialog('dialog');});", True)

this code works in page but not in user control. how can i fix it?

HTML Code :

'> ' runat="server" />

Not sure whether this is the issue or not. Since UserCOntrol is a naming container your element id might have changed. So you need to get the id using ClientID .

Change your code to something like this

$("#<%=yourbuttonid.ClientID%>").dialog("open");

Check the rendered HTML code of your page. Is the order of your script blocks correct? The setup block should be first there, and the showDialog call block should be rendered somewhere below it. Is it your case?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM