Monday, April 2, 2012

ASP.NET(JS Notify with C#)


//Step:01 Header Tags/Files
 <link type="text/css" rel="stylesheet" href="http://www.erichynds.com/examples/style.css" />
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" />
<link type="text/css" rel="stylesheet" href="ui.notify.css" />
<%-- <style type="text/css">form input { display:block; width:250px; margin-bottom:5px }</style>--%>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script>
<script src="src/jquery.notify.js" type="text/javascript"></script>

//Step:02 Body Tags<!--- container to hold notifications, and default templates --->
            <div id="container" style="display:none">
                <div id="default">
                      <h1>#{title}</h1>
                      <p>#{text}</p>
                </div>
            </div>
<!--- end container to hold notifications, and default templates --->


//Step:03 C# Code
#region Popup
    private void runjQueryCode(string Title, string Description)
    {
        ScriptManager requestSM = ScriptManager.GetCurrent(this);
        if (requestSM != null && requestSM.IsInAsyncPostBack)
        {
            ScriptManager.RegisterClientScriptBlock(this,
                                                    typeof(Page),
                                                    Guid.NewGuid().ToString(),
                                                    getjQueryCode(Title, Description),
                                                    true);
        }
        else
        {
            ClientScript.RegisterStartupScript(typeof(Page),
                                                   Guid.NewGuid().ToString(),
                                                   getjQueryCode(Title, Description),
                                                   true);
        }
    }

    private string getjQueryCode(string Title, string Description)
    {
        StringBuilder sb = new StringBuilder();
        sb.AppendLine("function create( template, vars, opts ){");
        sb.AppendLine("return $container.notify('create', template, vars, opts);");
        sb.AppendLine("}");
        sb.AppendLine("$(function(){");
        sb.AppendLine("$container = $('#container').notify();");
        sb.AppendLine("create('default', { title:'" + Title + "', text:'<br/>" + Description + "'});");
        sb.AppendLine("});");
        return sb.ToString();
    }
    #endregion

No comments:

Post a Comment