AJAX Control Toolkit's combobox + IE are too slow - c#

I have problems with optimizing AJAX Control Toolkit. The specific problem is that 4800 records take about 30 seconds to bind in Internet Explorer (only 2 seconds in Opera & Firefox). I've tried anything, but I still can't improve the load time in IE.
I've already enabled compression and caching, I'm using ToolkitScriptManager instead of ScriptManager. I've tried setting LoadScriptsBeforeUI and EnablePartialRendering to false, but it still doesn't help.
This is the query I use for binding.
var osoba =
from o in db.osobas
orderby o.osoba_prezime
select new {
o.osoba_id,
person = o.osoba_prezime + " " +
o.osoba_ime + " | " +
o.tijelo.tijelo_naziv + " | " +
o.radno_mjesto.rm_naziv_m
};
cb1.DataSource = osoba;
cb1.DataTextField = "person";
cb1.DataValueField = "osoba_id";
cb1.DataBind();
cb1.Items.Insert(0, " ");
Any help would be appreciated. Thank you!

Do you happen to have the developer toolbar open? I've had speed issues in IE when the toolbar is running, and when it's closed, load times are considerably faster.

Related

Receive the session in list Box in separate rows

hello m using visual studio 2012 , and trying to send session on different web page. its transferring my sessions but the problem is it is not showing in separate rows :( m using this code
Session["ProductName" + "\n"] += "\n" + ProductName; //this is on page 1
string pName = Convert.ToString(Session["ProductName" + "\n"]);
ListBox1.Items.Add("\n" + pName); //this one m using on targeted page
Use Environment.NewLine :
Session["ProductName" ] += Environment.NewLine + ProductName; //this is on page 1
Then you will not have to use "/n" in the other page Also.

how to know which browser my .net application is running on?

I want to apply different css on different browsers.
I want to run one css when it is safari and second for all others.
How can I detect that and apply css according to that?
You can use CSS browser selectors for this. There are different solutions available for this on the net.
For example:
CSS Browser Selector
The CSS Browser Selector is a small JavaScript library which allows you to include different cascading style sheets (CSS) for each browser.
An example:
<style type="text/css">
.ie .example {
background-color: yellow
}
.ie7 .example {
background-color: orange
}
.opera .example {
background-color: green
}
.webkit .example {
background-color: black
</style>
If you Google for "different css per browser" you'll find other solutions as well, but most of them boil down to similar solutions.
Another way would be to detect the browser type and capabilities in ASP.NET so that you can render the appropriate HTML / CSS / ...etc. You can find more information on that topic here:
http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx
For example:
private void Button1_Click(object sender, System.EventArgs e)
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform;
TextBox1.Text = s;
}
The Browser property of the Request returns a HttpBrowserCapabilities object. It contains information on the capabilities of the browser that is running on the client.
http://msdn.microsoft.com/en-us/library/system.web.httpbrowsercapabilities.aspx
You can examine the UserAgent property of the Request object.
Inside the page head tag
<%# Request.UserAgent.ToLower().Contains("safari") ?
"<link rel='stylesheet' type='text/css' href='safari.css' />" :
"<link rel='stylesheet' type='text/css' href='other.css' />" %>
Use below things....in your control...and you can set different style...to asp.net textbox control for different browser.
<asp:TextBox ID="TestTextBox" runat="server" ie:Text="You are in Internet explorer." mozilla:Text="You are in Firefox." Text="You are in other browser." ie:CssClass="IEStyle" mozilla:CssClass="FFStyle" CssClass="DefaultStyle" />
using Using the Request.Browser you can determine the browser user is using your
You can check it from javascript like:
if (navigator.appName == 'Microsoft Internet Explorer') {
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}

WatIn Add a new option to a Selectlist?

I need to add a new option to a selectList in one of my unit tests, and I can't figure out how to do it.
The Dropdown currently has 2 options, I want to add a third, and use it.
I tried to use JavaScript injection using http://stevenharman.net/blog/archive/2007/07/10/add-option-elements-to-a-select-list-with-javascript.aspx as a base, but that failed. I get exceptions that crash the IE browser every time, and the text "RunScript failed" gets printed into my logs even though I don't use that text in my error output.
Is this possible in Watin? Or has Open Source Failed me?
Using the code in the link you provided, with one small change I've gotten it to work.
My changes
Changed the ID to the ID of my dropdown (of course!)
Changed the $ in the element get to 'document.getElementById'. With the $ in there instead I don't see any obvious errors or anything like that; just no action taken.
The 'New Option' is added to the dropdown as the last item and it is the selected item.
string js = "";
js = js + "var theSelectList = document.getElementById('myDropDownID'); ";
js = js + " AddSelectOption(theSelectList, \"My Option\", \"123\", true);";
js = js + " function AddSelectOption(selectObj, text, value, isSelected) ";
js = js + "{";
js = js + " if (selectObj != null && selectObj.options != null)";
js = js + "{";
js = js + " selectObj.options[selectObj.options.length] = new Option(text, value, false, isSelected);";
js = js + "}}";
myIE.Document.Eval(js);
My setup
WatiN 2.0
IE8
Win7
Checked when the dropdown has 1 entry and 2 entries; both scenarios had "My Option" added without issue.

YUI AJAX and .Net MVC

I'm having a bit of an issue with a mix between YUI's AJAX and a YUI Datatable. The AJAX request fires properly and I get back the correct data formatted as:
{NoteId:'" + result.NoteId + "', CreatedOn:'" + result.CreatedOn.ToShortDateString() +
"', UpdatedOn:'" + result.UpdatedOn.ToShortDateString() + "', CreatedBy:'" + result.CreatedBy +
"', NoteContent:'" + result.NoteContent + "'}
These match the table identities properly, and I ripped this formatting from the statement that initially creates the datatable (which works properly). I don't know if I have the 'onSuccess' messed up for my AJAX call or what, and this is my first time touching YUI.
Also, if I manually execute the noteTable.addRow and hard code the data, it works.
Code for the AJAX call and Table Update:
function addNote() {
var noteText = editor.get('element').value;
var id = '<%= Model.Menu.Level1Tab %>'
var lpqId = <%= Model.LpqID %>
var sUrl = "/Lpm/Notes";
var callback = {
success: function(o) {
noteTable.addRow(o.responseText);
},
failure: function(o) {
}
}
var transaction = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, 'id=' + id + '&noteContent=' + noteText + '&noteId=' + noteId + '&lpqId=' + lpqId);
}
I'm pretty well stuck on this, so if anyone could have a look and let me know where I messed something up, I'd appreciate it. If you need more info, I have plenty, including firebug debugging info.
Thanks in advance for the help
Looks like you need to convert the o.responseText from string to object. The JSON Utility can help you do that: http://developer.yahoo.com/yui/json/.
Incidentally, DataTable's DataSource integration can help manage these issues for you. This example (http://developer.yahoo.com/yui/examples/datatable/dt_xhrjson.html) shows you how to set up a DataSource and integrate it with a DataTable. Note how you can send a request to get some data from your server and then use one of the "onDataReturn..." methods (see "Loading data at runtime" under http://developer.yahoo.com/yui/datatable/#data) in your callback.

Creating a customized "Yes / No" alert box in asp.net (javascript) - Part 2

I am trying to create a customized messagebox using javascript but not getting too far.
string txtConfirmMessage = "On " + DateTime.Now + ", ";
txtConfirmMessage = txtConfirmMessage + sUserID;
txtConfirmMessage = txtConfirmMessage + " added this record. Do you want to continue? ";
btnSubmit.OnClientClick = #"return confirm('" + txtConfirmMessage + "' Do you want to continue);";
I need to display a custom message involving the UserID, the date, and the value that the user has enetered. When I click the Submit button, the messagebox does not pop up.
Update:
I know this code is executed at the Page_Load event. However, is it possible to display in this alert box, a value that the user has selected (that action occurs after the page load event) ?
Any ideas to resolve this issue?
The javascript that you have is not valid, as the "confirm" method taks a single parameter, but you are giving it two bits.
Try this modified version.
string messageFormat = "On {0}, {1} added this record. Do you want to continue?";
string formattedMessage = string.format(messageFormat, DateTime.Now, sUserID);
btnSubmit.OnClientClick = "return confirm('" + formattedMessage + "');";
You just have an extra string after the one you're passing to confirm(), change it to this:
btnSubmit.OnClientClick = #"return confirm('" + txtConfirmMessage + "');";
About the update of the question, you could assign an OnClientClick event handler to the button as late as PreRender and the value will be persisted in the ViewState.

Categories