zoukankan      html  css  js  c++  java
  • Passing Parameters To Modal Dialog From Code Behind

    We often use modal dialog to display list item or other infomation in sharepoint.we can use the following code to create a modal dialog:

    View Code
     1 <script type="text/javascript">
    2 function ShowInfo() {
    3 var options = SP.UI.$create_DialogOptions();
    4
    5 options.title = "ModalDialogTitle";
    6 options.width = 800;
    7 options.height = 400;
    8 options.url = "/_layouts/***.aspx";
    9
    10 SP.UI.ModalDialog.showModalDialog(options);
    11 }
    12 </script>

    Most of the time,we need to pass one or more parameters to it,so we change the code like this:

    View Code
     1 <script type="text/javascript">
    2 function ShowEmpInfo(para, title) {
    3 var options = SP.UI.$create_DialogOptions();
    4
    5 options.title = title;
    6 options.width = 800;
    7 options.height = 400;
    8 options.url = "/_layouts/***.aspx?para=" + para;
    9
    10 SP.UI.ModalDialog.showModalDialog(options);
    11 }
    12 </script>

    But how to pass these parameters,we can do it like this.

    Suppose that we have a button,and we want to click it to show the special infomation,pass its ToolTip property to the parameter "para" and Text property to "title",we can add a "OnClick" event to this button,and write the following code to the code behind:

    View Code
     1 protected void btn_OnClick(object sender, EventArgs e)
    2 {
    3 btn_Info_onclick(((Button)sender).ToolTip, ((Button)sender).Text, (Button)sender);
    4 }
    5
    6 protected void btn_Info_onclick(string para, string title, Button btn)
    7 {
    8 // create ECMAScript to call the dialog function and pass the parameters
    9 var script = string.Format(@"ShowEmpInfo('{0}','{1}'); ", para, title);
    10 // run the script
    11 ScriptManager.RegisterStartupScript(btn.Page, this.GetType(), "onekey", script, true);
    12 }
  • 相关阅读:
    PHP通用函数
    Discuz 取各排行榜数据
    htaccess 增加静态文件缓存和压缩
    一个域名解析不同访问方法
    TP5:隐藏inde.php文件
    vscode:解决操作git总让输入用户名及密码问题
    vscode:配置git
    cmd:相关命令和笔记
    PHP:通过MVC,实现第三方登录(百度)
    Linux:301重定向 —— 将不带www的重定向到带www的
  • 原文地址:https://www.cnblogs.com/leolis/p/2366973.html
Copyright © 2011-2022 走看看