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 }
  • 相关阅读:
    Gyp语法规则参考 & 工具的使用
    从源码编译Chrome(chromium)
    Oracle 高版本导出到低版本的测试验证
    CentOS7 安装Oracle11g的过程.
    Rhino 使 JavaScript 应用程序更灵动(转载)
    javascript与java的相互调用,纯java的javascript引擎rhino(转载)
    Template Method Design Pattern in Java
    Chain Of Responsibility Design Pattern Example
    设计模式之状态模式
    设计模式之装饰者模式
  • 原文地址:https://www.cnblogs.com/leolis/p/2366973.html
Copyright © 2011-2022 走看看