Home > ASP.Net, Javascript, Jquery > Show JQuery Dialog Window With Redirect from Code behind

Show JQuery Dialog Window With Redirect from Code behind


Hi all,

try this example to display JQuery Dialog Window with Redirect on close button from Code behind


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default10.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title>JQuery Dialog With Redirect On Close</title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
 <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
 rel="stylesheet" type="text/css" />
</head>
<body>
 <form id="form1" runat="server">
 <div id="alertdialog" style="display: none">
 </div>
 </form>
</body>
</html>

In code behind :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
 private void ShowAlert(string message, string url)
 {
 ///Initialize the stringbuilder object to append JS script
 StringBuilder sb = new StringBuilder();
 sb.Append("$(function() { ");
 sb.Append("$('#alertdialog').empty();");
 sb.Append("$('#alertdialog').append('" + message + "');");
 sb.Append(" $('#alertdialog').dialog({");
 sb.Append(" width: 350,");
 sb.Append("buttons: {");
 sb.Append("'close': function(event, ui) { window.location.href = '" + url + "'; }");
 sb.Append(" }");
 sb.Append(" });");
 sb.Append("});");
 ///Register the script on page startup
 ClientScript.RegisterStartupScript(typeof(Page), "myscript", sb.ToString(), true);
 }

protected void Page_Load(object sender, EventArgs e)
 {
 ShowAlert("your message here", "page.htm");
 }
}

Hope this helps

Good Luck

 

Advertisements
Categories: ASP.Net, Javascript, Jquery
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: