Fail to initiate connection in Signal R in asp.net - asp.net

Below is my .aspx page code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="chat.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script src="Scripts/json2.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-1.0.0-rc2.min.js" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
var query = window.location.search;
var toRemove = '?id=';
var gorge = query.replace(toRemove, '');
// Proxy created on the fly
var hub = $.connection.chatHub;
$.connection.hub.qs = "Id=" + gorge;
// Start the connection
$.connection.hub.start(function () {
//chat.server.getAllOnlineStatus();
});
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="container" class="wrap">
<div id="chatbox" class="chatbox">
<ul id="frndcontact">
</ul>
</div>
</div>
</form>
</body>
</html>
Below is my Hub class
[HubName("chatHub2")]
public class Chat2 : Hub
{
private SqlConnection objconn;
string Connstr = #"Data Source=somevalue;Initial Catalog=somevalue;Integrated Security=True;";
public Task JoinGroup()
{
return Groups.Add(Context.ConnectionId, "foo");
}
public DataTable GetDataTable(string strQuery)
{
SqlCommand objcmd;
SqlDataAdapter objda;
DataTable ds = new DataTable();
try
{
objconn = new SqlConnection(Connstr);
objconn.Open();
objcmd = new SqlCommand(strQuery, objconn);
objda = new SqlDataAdapter(objcmd);
objda.Fill(ds);
return ds;
}
catch (SqlException ex)
{
throw ex.InnerException;
}
finally
{
objconn.Close();
objcmd = null;
objda = null;
}
}
public override Task OnConnected()
{
int id = Convert.ToInt32(Context.QueryString["id"]);
string sql = string.Format("exec getfriend '" + id + "' ");
System.Data.DataTable dtgetfriend = GetDataTable(sql);
}}
Now when I am debugging I am not able to get my breakpoint hit on OnConnected. Why am I not able to start with this piece of code?
Also I have added this code in global.asax
public void Application_Start()
{
RouteTable.Routes.MapHubs();
}

You're not subscribed to the hub. Prior to start you need to declare at least one client side function and you need to reference your hub by the correct name. So if you modify your JS to be:
$(document).ready(function () {
var query = window.location.search;
var toRemove = '?id=';
var gorge = query.replace(toRemove, '');
// Proxy created on the fly
var hub = $.connection.chatHub2;
$.connection.hub.qs = "Id=" + gorge;
hub.client.foo = function() {};
// Start the connection
$.connection.hub.start(function () {
//chat.server.getAllOnlineStatus();
});
});
You'll be in good shape.

Related

Signalr and Devexpress

I want to create a grid and automatic update it, when data changes in the database. It works with a simple table control.
public partial class index : System.Web.UI.Page
{
static string connectionString = #"Data Source=*******;initial catalog=Test;persist security info=True; Integrated Security=SSPI;";
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static IEnumerable<Person> GetData()
{
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(#"SELECT [Id],[Name] FROM [dbo].[Persons]", connection))
{
command.Notification = null;
SqlDependency.Start(connectionString);
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(Dependency_OnChange);
if (connection.State == ConnectionState.Closed)
connection.Open();
using (var reader = command.ExecuteReader())
return reader.Cast<IDataRecord>()
.Select(x => new Person(x.GetInt32(0), x.GetString(1))).ToList();
}
}
}
private static void Dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
MyHub.Show();
}
public void FillGrid()
{
List<Person> persons = new List<Person>();
using (var connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(#"SELECT [Id],[Name] FROM [dbo].[Persons]", connection))
{
if (connection.State == ConnectionState.Closed)
connection.Open();
using (SqlDataReader rdr = command.ExecuteReader())
{
while (rdr.Read())
{
var id = rdr.GetInt32(0);
var name = rdr.GetString(1);
persons.Add(new Person(id, name));
}
}
}
}
grid.DataSource = persons;
grid.DataBind();
}
}
public class MyHub : Hub
{
public static void Show()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.All.displayStatus();
}
}
And the apsx Page :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-2.2.2.min.js"></script>
<script src="signalr/hubs"></script>
<script type="text/javascript">
$(function () {
// Proxy created on the fly
var job = $.connection.myHub;
// Declare a function on the job hub so the server can invoke it
job.client.displayStatus = function () {
getData();
};
// Start the connection
$.connection.hub.start();
getData();
});
function getData()
{
var $tbl = $('#tbl');
$.ajax({
url: '/index.aspx/GetData',
contentType: 'application/json;charset=utf-8',
datatype: 'json',
type: 'POST',
success: function (data) {
if (data.d.length > 0) {
var newdata = data.d;
$tbl.empty();
$tbl.append(' <tr><th>ID</th><th>Name</th></tr>');
var rows = [];
for (var i = 0; i < newdata.length; i++) {
rows.push(' <tr><td>' + newdata[i].Id + '</td><td>' + newdata[i].Name + '</td><td></tr>');
}
$tbl.append(rows.join(''));
}
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="tbl"></table>
<dx:ASPxGridView ID="grid" runat="server"></dx:ASPxGridView>
</div>
</form>
</body>
</html>
However I want to use a Devepress Aspxgridview. The Devexpress Site states they don't support SignalR. However since the Javascript function is triggered when data changes in the database, is it possible somehow to force the client to get the data from the server? Force a postback and/or call the FillGrid method? ( To create the grid from js is not possible since the AspxgridView Control is much more complicated).
SOURCE: https://www.youtube.com/watch?v=30m-7wpmbrc
Although SignalR is not supported out of the box, it should be possible to manually notify the server side about the update using the existing API. You can send a callback to the server using the ASPxClientGridView.PerformCallback method, and handle the server side ASPxGridView.CustomCallback event to reload data from the SQL server.

SignalR sqlDependency

I need SQL Dependency change on a gridview displaying all rows that are changed or old data. Can anybody help me?
Here is my script:
<script>
$(function () {
var notify = $.connection.notificationsHub;
notify.client.displayNotification = function (msg) {
$("#newData").html(msg);
};
$.connection.hub.start();
});
</script> </head> <body>
<form id="form1" runat="server">
<div>
<asp:GridView id="newData" runat="server" AutoGenerateColumns="False">
</asp:GridView>
public void SendNotifications()
{
string message = string.Empty;
string conStr = ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString;
using (SqlConnection connection = new SqlConnection(conStr))
{
string query = "SELECT [Message] FROM [dbo].[tb]";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Notification = null;
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
message = reader.GetString(0);
}
}
}
}
NotificationsHub nHub = new NotificationsHub();
nHub.NotifyAllClients(message);
}
private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
SendNotifications();
}
}

How to show Arabic style in Google charts

<%# Page Language="C#" AutoEventWireup="true" CodeFile="Ar_PieChart.aspx.cs" Inherits="Ar_PieChart" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<meta http-equiv='content-type' content='text/html; charset=UTF-16' />
<meta name="viewport" content="width=device-height,minimum-scale=0.5,maximum-scale=3.0,user-scalable=yes" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', { packages: ['corechart'] });
</script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: 'POST',
dataType: 'json',
contentType: 'application/json',
url: 'Ar_PieChart.aspx/GetData',
data: '{}',
success:
function (response) {
drawVisualization(response.d);
}
});
})
function drawVisualization(dataValues) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Column Name');
data.addColumn('number', 'Column Value');
for (var i = 0; i < dataValues.length; i++) {
data.addRow([dataValues[i].ColumnName, dataValues[i].Value]);
}
new google.visualization.PieChart(document.getElementById('visualization')).draw(data, { is3D: true });
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="visualization" style="width: 600px; height: 350px">
</div>
</form>
</body>
</html>
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.Data;
using System.Web.Services;
using MySql.Data.MySqlClient;
public partial class Ar_PieChart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static List<Data> GetData()
{
MySqlConnection conn = new MySqlConnection("server=****;user id=****;Password=****;database=****");
DataSet ds = new DataSet();
DataTable dt = new DataTable();
conn.Open();
string cmdstr = "SELECT Class,COUNT(Class) FROM sh_report GROUP BY Class";
MySqlCommand cmd = new MySqlCommand(cmdstr, conn);
MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
adp.Fill(ds);
dt = ds.Tables[0];
List<Data> dataList = new List<Data>();
string cat = "";
int val = 0;
foreach (DataRow dr in dt.Rows)
{
cat = dr[0].ToString();
val = Convert.ToInt32(dr[1]);
dataList.Add(new Data(cat, val));
}
return dataList;
}
}
public class Data
{
public string ColumnName = "";
public int Value = 0;
public Data(string columnName, int value)
{
ColumnName = columnName;
Value = value;
}
}
I am getting chart perfectly but i am in need of Arabic style like reverse.
i mean while seeing the chart view in mirror.
If any one know the answer please help me.
Thanks in advance.

Database notification using signalr and asp.net not displaying the data in UI

i followed the tutorial to from one of the online blog and am able get the application out with out error, but main issue is its not giving error as well as output.
My hub class looks like this
public void NotifyAllClients(string msg)
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationsHub>();
context.Clients.All.displayNotification(msg);
}
My ASPX.CS page looks like this
protected void Page_Load(object sender, EventArgs e)
{
SendNotifications();
}
public void SendNotifications()
{
string message = string.Empty;
string conStr = ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString;
using (SqlConnection connection = new SqlConnection(conStr))
{
string query = "SELECT [Message] FROM [dbo].[MessageBuffer]";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Notification = null;
SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
message = reader[0].ToString();
}
}
}
NotificationsHub nHub = new NotificationsHub();
nHub.NotifyAllClients(message);
}
private void dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
SendNotifications();
}
}
and My aspx page is --
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script src="Scripts/jquery-1.8.2.min.js"></script>
<script src="Scripts/jquery.signalR-2.1.2.js"></script>
<script src="signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var notify = $.connection.notificationsHub;
notify.client.displayNotification = function (msg) {
$('#newData').append('<li><strong>' + msg + '</li>');
};
$.connection.hub.start();
});
</script>
<div style="padding:10px 0px 10px 10px">
New Messages:
<ul id="newData"></ul>
</div>
</body>
</html>
i have done different samples, i have used same format to display, i am able to get those out in a hand, but here i am stuck with this. i am getting value in aspx.cs page, it calling the DB, which i have given in global.asax. and i have added sqldependency as well, enbabled broker in DB. but issue is still there. i cant see anything in UI.
Thanks in advance
I had a similar problem a while back. I just used the hub method name attribute and it worked for me. So you want something like
[HubMethodName("SendNotifications")]
public string SendNotifications()
And then at the front end just do
$.connection.hub.start(function () {
notify.server.SendNotifications();
});
Update
You could have a span the way I have in my code. so something like
<div>
<ul>
<li>New Messages:<span id="newData">0</span></a></li>
</ul>
</div>
Then do
$('#newData').text(msg);

CustomControl for Team WebAccess --> jQuery doesnt work

I recently ran into some similar issue I think.
I am developing a custom control for Team WebAccess 2010: The MultiValueControl for the browser. To achieve the very same experience as the MultiValueControl of the witcontrolsuite. (http://witcustomcontrols.codeplex.com/wikipage?title=Multivalue%20control&referringTitle=Home)
Therefore I am using an asp.net server control with a listbox (which is rendered as a html ) along with the following jquery drowdownchecklist (http://code.google.com/p/dropdown-check-list/)
the servercontrol looks like the following
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CodePlex.WitCustomControls.WebAccess.MultiValueControl
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:MultiValueControl runat=server></{0}:MultiValueControl>")]
public class MultiValueControl : WebControl
{
public ListBox MyListBox { get; set; }
protected override void CreateChildControls()
{
base.CreateChildControls();
MyListBox = new ListBox();
MyListBox.SelectionMode = ListSelectionMode.Multiple;
MyListBox.Items.Add(new ListItem("abcd 1"));
MyListBox.Items.Add(new ListItem("abcd 2"));
MyListBox.Items.Add(new ListItem("abcd 3"));
MyListBox.Items.Add(new ListItem("abcd 4"));
MyListBox.Items.Add(new ListItem("abcd 5"));
this.Controls.Clear();
this.Controls.Add(MyListBox);
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string resourceName1 = "WebApplication1.embedded.jquery-1.4.2.min.js";
string resourceName2 = "WebApplication1.embedded.jquery-ui-1.8.4.custom.min.js";
string resourceName3 = "WebApplication1.embedded.ui.dropdownchecklist.js";
ClientScriptManager cs = this.Page.ClientScript;
var t = typeof(MultiValueControl);
cs.RegisterClientScriptResource(t, resourceName1);
cs.RegisterClientScriptResource(t, resourceName2);
cs.RegisterClientScriptResource(t, resourceName3);
string csslink = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "WebApplication1.embedded.ui.dropdownchecklist.standalone.css")
+ "' rel='stylesheet' type='text/css' />";
var include = new LiteralControl(csslink);
this.Page.Header.Controls.Add(include);
string csslink2 = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "WebApplication1.embedded.ui.dropdownchecklist.themeroller.css")
+ "' rel='stylesheet' type='text/css' />";
var include2 = new LiteralControl(csslink2);
this.Page.Header.Controls.Add(include);
var csType = typeof(MultiValueControl);
var csName = "MultiValueControl" + MyListBox.ClientID;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(csType, csName))
{
StringBuilder csText = new StringBuilder();
csText.Append("<script type=\"text/javascript\">");
//we need to write the code the following way
csText.Append("(function($) { $(document).ready(function() {$(\"#" + this.MyListBox.ClientID + "\").dropdownchecklist();}); })(jQuery);");
//does not work as $ sign is not associated with jQuery in Team WebAccess!
//csText.Append(" $(document).ready(function() {$(\"#" + this.MyListBox.ClientID + "\").dropdownchecklist();});");
csText.Append("</script>");
cs.RegisterClientScriptBlock(csType, csName, csText.ToString());
}
}
}
}
As you can see, I inject the scripts (which are embedded in the controls assembly) into the output page in the pre-render step.
When I run all this on an asp.net application on my local computer (I created it to prototype my solution) it works perfectly...
However that control does not work with Team WebAccess 2010, as I get the error message 'jQuery' is undefined
However when I look at my page, I can definetly see, that the three scripts I inject are just perfectly well added just before the script that throws the error:
<script src="/tfs/web/WebResource.axd?d=yGr4pF28N1gYPBSvcQ65PxwkQdtFV1bc0SJjY2M7nTK9BloSmvQxu8btRw7YDdXsjbAwSZPJBiIDI-3FSC7yFCXHjuvhkhaTAlTv2uOnOhR_y_2fLK1ahIdVYiXjEjDT2ZEI9_ozHhoJqICZykZo_rBCIDp5h7Y8v6-zWJJDJoqIIHI47YpQDhsE4-_UcYV6b6G-Cgr8MWH9AEP7CtK7Ie6wWCU1&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=9iAfN71_Hpv7igrtbh4h9pBAMBHXqUC1cX5cjkAEr1PglPvi4Uo5KLOC6tuHzMyGkpHEeBXbVeIX_NGIiKlHPSNlOjw75DksE2F-2NMVlIXoEB4uVTvyTwvt1TM3S2AGLY13hLPmM-SW12g3ZGU28PC23Vx_aYAFWSco6hgPTcCBOPuw4nSNSI72kgVuMwBjhzjxVbbzhdGLxrSAodBH5g7PATsuAN7CHE8vmi_pk9f8mW-50&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=c_BidQPb2wjtuw09st9ilCtRhA4VEjgNgJgr0VlFIRdKYP2UK1AqWS8Mo3AEiDU_MMCZkwjMVa1tTKg9UlpFoCqxCzKUhCK7Moou4ywZ74S0FJvdrcJ1cGbqtZnxrfUBLbN8_iahrG2A9Fq55up3o6R2_SlFU4d_gb_4fBXnticOG8Bl4JCbq7F2PnG-rw0fTiNwGDMwZFv1RvNJerUGYo_0Wuw1&t=634306043180265615" type="text/javascript"></script>
<script type="text/javascript">(function($) { $(document).ready(function() {$("#ctl00_c_we_ctl47_ctl00").dropdownchecklist();}); })(jQuery);</Script>
The following is the source of the page (up to my injected scripts) that does not work. (of course I dummied the fqdn name of the server ;-))
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
New Change Request: - Team Web Access
</title>
<base target="_self" />
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/tfs/web/WebResource.axd?d=fLgM8VwLkwzQwVHlt0I3zfY4k-15sHec44H9BY54wjS_v_rJDRkLrbhLIvED-zHvir1koHstEWBv_Erm3BGVmScM6OA1&t=634210436612724343" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[var JSConfig ={"showBrowserToolbar":true};//]]></script>
<script src="/tfs/web/Resources/Scripts/WindowHelpers.js" type="text/javascript"></script>
<script src="/tfs/web/Resources/Scripts/DocumentService.js" type="text/javascript"></script>
<script src="/tfs/web/ScriptResource.axd?d=DUMMYVALUE"></script>
<script type="text/javascript">
//<![CDATA[
$jslimg("imga8521f38",["/tfs/web/App_Themes/Default/Images/h-progress.gif","/tfs/web/App_Themes/Default/Images/spinner.gif","/tfs/web/App_Themes/Default/Images/tmih.gif"]);//]]>
</script>
<script src="/tfs/web/Resources/Scripts/WindowToolbar.js" type="text/javascript"></script>
<script src="/tfs/web/Resources/Scripts/SearchHelper.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
$new(windowToolbar,"ctl00_wtb",["ctl00$wtb",{"pguid":"e591d5c5-c3bd-4431-81cc-62b4fc5a6b81"}]);
//]]>
</script>
<script src="/tfs/web/Resources/Scripts/EditWorkItem.js" type="text/javascript"></script>
....
<script type="text/javascript">
//<![CDATA[
$jsreg("cd326c372",{"changeCallbackEventName":"FieldChanged","numberFormat":"None"});
$jsreg("c384acf1b",{"dropCount":8,"minDropPanelWidth":0,"maxDropPanelWidth":0,"notAllowedBGColor":"#FFFFCC","allowedBGColor":"","textBoxClass":"tswa-text-box","textBoxDisabledClass":"tswa-text-box-disabled","dropPanelClass":"tswa-font tswa-dropdowncanvas","listItemClass":"tswa-listitem","listItemHoverClass":"tswa-listitemhover","listItemSelectedClass":"tswa-listitemselected","listItemDisabledClass":"tswa-listitemdisabled","decimalChar":","});
$jsreg("c569d08c7",[]);
$new(editableDropDown,"ctl00_c_we_ctl04_wc_val",[5,cd326c372,null,c384acf1b,null,c569d08c7,c569d08c7,c569d08c7,null,"",null,""]);
//]]>
</script>
<script src="/tfs/web/WebResource.axd?d=yGr4pF28N1gYPBSvcQ65PxwkQdtFV1bc0SJjY2M7nTK9BloSmvQxu8btRw7YDdXsjbAwSZPJBiIDI-3FSC7yFCXHjuvhkhaTAlTv2uOnOhR_y_2fLK1ahIdVYiXjEjDT2ZEI9_ozHhoJqICZykZo_rBCIDp5h7Y8v6-zWJJDJoqIIHI47YpQDhsE4-_UcYV6b6G-Cgr8MWH9AEP7CtK7Ie6wWCU1&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=9iAfN71_Hpv7igrtbh4h9pBAMBHXqUC1cX5cjkAEr1PglPvi4Uo5KLOC6tuHzMyGkpHEeBXbVeIX_NGIiKlHPSNlOjw75DksE2F-2NMVlIXoEB4uVTvyTwvt1TM3S2AGLY13hLPmM-SW12g3ZGU28PC23Vx_aYAFWSco6hgPTcCBOPuw4nSNSI72kgVuMwBjhzjxVbbzhdGLxrSAodBH5g7PATsuAN7CHE8vmi_pk9f8mW-50&t=634306043180265615" type="text/javascript"></script>
<script src="/tfs/web/WebResource.axd?d=c_BidQPb2wjtuw09st9ilCtRhA4VEjgNgJgr0VlFIRdKYP2UK1AqWS8Mo3AEiDU_MMCZkwjMVa1tTKg9UlpFoCqxCzKUhCK7Moou4ywZ74S0FJvdrcJ1cGbqtZnxrfUBLbN8_iahrG2A9Fq55up3o6R2_SlFU4d_gb_4fBXnticOG8Bl4JCbq7F2PnG-rw0fTiNwGDMwZFv1RvNJerUGYo_0Wuw1&t=634306043180265615" type="text/javascript"></script><script type="text/javascript">(function($) { $(document).ready(function() {$("#ctl00_c_we_ctl49_ctl00").dropdownchecklist();}); })(jQuery);</script>
<script type="text/javascript">(function($) { $(document).ready(function() {$("#ctl00_c_we_ctl52_ctl00").dropdownchecklist();}); })(jQuery);</script>
I just have no more clues what I can do! Please HELP!!
Try putting the script registrations in the page init(). This worked for me.
Ok... as noone seemed to be able to help me, I finally could solve the problem on my own. However I am not sure if this is a sober approach. Well at least it works, right? :)
What I did was changing the "prerender" logic to not register the jQuery libs as web resource but writing them out like my own client side script.
Its rather hard to explain - so just look at the code.
base.OnPreRender(e);
// jquery control only works together with listbox
if (!(this.CheckboxList is ListBox))
return;
string resourceName1 = "CodePlex.WitCustomControls.WebAccess.embedded.jquery-1.4.2.min.js";
string resourceName2 = "CodePlex.WitCustomControls.WebAccess.embedded.jquery-ui-1.8.4.custom.min.js";
string resourceName3 = "CodePlex.WitCustomControls.WebAccess.embedded.ui.dropdownchecklist.js";
ClientScriptManager cs = this.Page.ClientScript;
var t = typeof(MultiValueControl);
WriteEmbeddedScript(cs, resourceName1, t);
WriteEmbeddedScript(cs, resourceName2, t);
WriteEmbeddedScript(cs, resourceName3, t);
//cs.RegisterClientScriptResource(t, resourceName1);
//cs.RegisterClientScriptResource(t, resourceName2);
//cs.RegisterClientScriptResource(t, resourceName3);
string csslink = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "CodePlex.WitCustomControls.WebAccess.embedded.ui.dropdownchecklist.standalone.css")
+ "' rel='stylesheet' type='text/css' />";
var include = new LiteralControl(csslink);
this.Page.Header.Controls.Add(include);
string csslink2 = "<link href='"
+ Page.ClientScript.GetWebResourceUrl(t, "CodePlex.WitCustomControls.WebAccess.embedded.ui.dropdownchecklist.themeroller.css")
+ "' rel='stylesheet' type='text/css' />";
var include2 = new LiteralControl(csslink2);
this.Page.Header.Controls.Add(include);
var csType = typeof(MultiValueControl);
var csName = "MultiValueControl" + CheckboxList.ClientID; // we need to add a script for each separate MultiValueControl on a page
var script = "(function($) { $(document).ready(function() {$(\"#" + this.CheckboxList.ClientID + "\").dropdownchecklist();}); })(jQuery);";
WriteScript(cs, script, csType, csName);
}
private static void WriteEmbeddedScript(ClientScriptManager cs, string resourceName1, Type t)
{
using (var reader = new StreamReader(Assembly.GetAssembly(t).GetManifestResourceStream(resourceName1)))
{
var script = reader.ReadToEnd();
WriteScript(cs, script, t, resourceName1);
}
}
private static void WriteScript(ClientScriptManager cs, string script, Type csType, string csName)
{
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(csType, csName))
{
StringBuilder csText = new StringBuilder();
csText.Append("<script type=\"text/javascript\">");
//we need to write the code the following way
csText.Append(script);
//does not work as $ sign is not associated with jQuery in Team WebAccess!
//csText.Append("$(document).ready(function() {$(\"#" + this.CheckboxList.ClientID + "\").dropdownchecklist();});");
csText.Append("</script>");
cs.RegisterClientScriptBlock(csType, csName, csText.ToString());
}
}

Resources