I'm using the auto complete control here:http://www.ramirezcobos.com/labs/autocomplete-for-jquery-js/comment-page-2/
And i've modified it as:
var json_options;
json_options = {
script:'ReportSearch.aspx/GetUserList?json=true&limit=6&',
varname:'input',
json:true,
shownoresults:true,
maxresults:16,
callback: function (obj) { $('#json_info').html('you have selected: '+obj.id + ' ' + obj.value + ' (' + obj.info + ')'); }
};
$('#ctl00_contentModule_txtJQuerySearch').autoComplete(json_options);
I have the following method in C# Code behind (aspx.cs)
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetUserList(string input)
{
List<string> lUsers = new List<string>();
Server.DAL.SQLServer2005.User user = new Server.DAL.SQLServer2005.User();
Server.Info.AuthUser aUser = (Server.Info.AuthUser)HttpContext.Current.Session["AuthUser"];
List<Server.Info.User.UserDetails> users = user.GetUserList(aUser, input, 16, true);
users.ForEach(delegate(ReportBeam.Server.Info.User.UserDetails u)
{
lUsers.Add("(" + u.UserName + ")" + u.LastName + ", " + u.FirstName);
});
return lUsers.ToArray();
}
The error I get back is:
Server Error in '/WebPortal4' Application. Unknown web method
GetUserList. Parameter name: methodName
If I change any of the paraemeter names I get an error telling me the paremeter names are not in match. now that everything is as it should, it's bombing.
Any help would rock.
If your code is in a user control, (and not in the actual aspx), that might cause problems. I guess it shouldn't, but I've had problems with it myself, don't remember exactly how they looked, but in the end I retorted to placing my web methods in asmx files instead of aspx files, if they are to be reached from anything but the aspx itself, and it's been working out great =)
Related
SOLVED
The problem was sending the number with double quotes like "40".
So I replaced quotes with empty space and It worked.
This is the code.
HRMID = HRMID.Replace('"', ' ').Trim();
I am trying to call my REST service consecutively but only one of them is working when I do that.
If I call only one of them in one block it works but two of them in one function block is causing problems I think,I don't know why.
Maybe it is something about restriction in the service.
There is no Error just it is not updating the Database.
If I use it alone it works so call is correct.
This is my code , I am waiting for suggestions.
Thanks!
private void GameClosed(object sender, EventArgs e)
{
// Do your stuff when the game closed.
try
{
var client = new WebClient();
var result = client.DownloadString(wsUrl + "/rest/gethrmid/" + UserValues[4]);// Only the first REST API call is working.This one works.
MessageBox.Show("Result is :" + result);
string HRMID = result;
StreamReader SR = new StreamReader("D:/HRMSession.txt");
string hrmValues = SR.ReadToEnd();
client.DownloadString(wsUrl + "/rest/inserthrmsession/" + HRMID + "/" + hrmValues);//This one is not working if i put here.
}
catch (Exception a)
{
MessageBox.Show(a.ToString());
}
}
EDIT:
If I write it as hardcoded it works but if I use the value that is coming from first call it doesn't work.
client.DownloadString(wsUrl + "/rest/inserthrmsession/" + 40 + "/" + hrmValues);//Works.
But I can not convert the value of HRMID to Int because operation contract is string...
I'm trying to design a webpart that looks at a list of news items, and initially prints all the rows in order by date. If the user selects a type of news item, then only those news items will be displayed (again, in order by date). The problem is that my webpart keeps throwing up this error when I try to debug it:
Microsoft JScript runtime error: Unknown runtime error
And this mess pops up behind it:
RTE.RteUtility.$1n = function($p0, $p1) {
if (RTE.RteUtility.isInternetExplorer() && $p0.tagName === 'TABLE') {
var $v_0 = document.createElement('DIV');
$v_0.innerHTML = '<table>' + $p1 + '</table>';
while ($p0.childNodes.length > 0) {
$p0.removeChild($p0.childNodes[0]);
}
RTE.RteUtility.$1E($v_0.firstChild, $p0);
}
else {
$p0.innerHTML = '<div>RTE</div>' + $p1;
$p0.removeChild($p0.firstChild);
}
}
The line: "$p0.innerHTML = 'RTE' + $p1" seems to be causing the problem. Well, otherwise, that's a really specific error message, thanks Microsoft. :/
The error seems to happen after CreateChildControls is called by NewsFeed.cs. My best theory right now is maybe something in NewsFeedUserControl.ascx.cs is causing an error, but as I'm a total neophyte at SharePoint I have no idea what that could possibly be. Is it because of this code in Page_Load?
protected void Page_Load(object sender, EventArgs e)
{
list = web.Lists["NewsFeedLI"];
query.Query = "<Where><IsNotNull><FieldRef Name='Headline' /></IsNotNull></Where></Query>" +
"<OrderBy<FieldRef Name='Article_x0020_Date' Ascending='True' /></OrderBy>";
SPListItemCollection result = list.GetItems(query);
foreach (SPListItem item in result)
{
newsList.Text = newsList.Text + item["Headline"].ToString() + Environment.NewLine;
newsList.Text = newsList.Text + item["Summary"].ToString() + Environment.NewLine + Environment.NewLine;
}
}
See, I don't know.
Try predefining the text that you return in your loop. If the web part looks OK with basic text (e.g. "Hello World") but not with more advanced values then that it where your problem lies.
You will want to ensure that you apply the appropriate encoding to any output you are rendering to the screen as this may be causing you issues.
I have troubles with adding blocks with a specific attributes on my asp.net mvc project using jquery.
I need to add block into the page depending on what i have in a dropdownlist(created via c#)
I had created a hidden block in my view(view the code below) wich makes "select" tag with options from my "List"
<div id="other" class="EqItem">
<p>Else: #Html.DropDownList("else", Model.ModEq("",""))</p>
<p>Serial №: #Html.TextBox("serialelse")</p>
</div>
After loading the page i use a function which removes this block from DOM and makes the copy of html code of this block into a variable(blockToAdd )
function BlockDelete()
{
blockToAdd = $("#other").html();
$("#other").remove();
}
then i use this variable to dinamically add blocks into my page(the function below)
function ShowListEtc()
{
for (c = 0; c < 15; c++)
{
if (!$("#divotherlist" + c + "").length) {
id = "divotherlist" + c + "";
clas = "EqItem";
blockToAdd = blockToAdd.trim();
$(".rightside").append('<div id="' + id + '">' + blockToAdd
+ '<p><img id ="' + id + 'D"src="/Images/delete.png"
onclick="Delete(id)"></p></div>');
$("#" + id).attr('class', clas);
$("#"+id).show();
selectid = "othersel" + c;
$("#" + id).find("select").attr('id', selectid);
$('#' + selectid + ' option').each(function () {
this.setAttribute('id', TransL(this.text) + c);
this.setAttribute('onclick', 'MakeNameParent(id)')
});
break;
}
}
}
The point is that i try to change attributes within created block(append(') but they are not applying!
When i made the code first time, it worked, but suddenly it had stopped to work, then i tried to use .prepend instead of .append, it began to work for a while but after reopening the project, it had stopped to work again!
Please tell me what i've done incorrect!
Thank you!
I'm aware that there are easier ways to do this and believe me, I've tried them. I'm of course open to any suggestions =). You don't need to read the whole code, just the part that says where the problem lies. Also, I'm debbugging perl style so you guys can see. Oh and did I mention that on my development environment everything works as intended?
Here's the code:
string GetPortalAlias()
{
String myURL2 = Request.Url.ToString();
URLLabel.Text = "Original Request.Url.ToString() returned: \"" + myURL2 + "\"";
string myURL = string.Copy(myURL2);
URLLabel.Text = "Copying it to myURL, it's now: \"" + myURL + "\"";
myURL = myURL.ToLower().Trim();
URLLabel.Text += "<br>Trimming and ToLower myURL.<br>The new url is \"" + myURL + "\"" + "<br>";
myURL = myURL.Replace(":80", "");
URLLabel.Text += "Replacing the \":80\".<br> The new url is\"" + myURL + "\"<br>";
//***HERE LIES THE PROBLEM***
myURL = myURL.Replace("http://", "");
URLLabel.Text += "Replacing the \"http://\".<br> The new url is\"" + myURL + "\"<br>";
//***PROBLEM ENDS***
myURL = myURL.Remove(myURL.IndexOf("/"));
URLLabel.Text += "Removing everything after the \"/\"." + "<br> The new url is \"" + myURL + "\"<br>";
URLLabel.Text += "<br>GetPortalAlias Returning \"" + myURL + "\"";
return myURL;
}
Believe it or not, the output produced in the webpage is this:
Copying it to myURL, it's now: "http://sar.smg.com.ar/Default.aspx?TabID=912"
Trimming and ToLower myURL.
The new url is "http://sar.smg.com.ar/default.aspx?tabid=912"
Replacing the ":80".
The new url is"http://sar.smg.com.ar/default.aspx?tabid=912"
Replacing the "http://".
The new url is"intranetqa/default.aspx?tabid=912"
Removing everything after the "/".
The new url is "intranetqa"
GetPortalAlias Returning "intranetqa"
So... for some reason whenever it reaches the replace section it mysteriously mutates to start with "intranetqa" instead of "sar.smg.com.ar". "intranetqa" is our default hostname. CHANGING OR TAKING AWAY ANY CHARACTER OF HTTP:// IN ANY WAY MUTATES THE STRING.
I do a string.copy because I'm aware that if two strings are equal the compiler stores them in the same place therefore I wanted to prevent errors. Taking those lines away and use Request.Url.ToString() tomyURL directly does nothing at all. They were just a test to see if that worked.
Here's a list of the things I've tried:
All combinations of string / String, none worked.
I've tried Request.Host.Url and it just gave me "intranetqa".
I've used Request.Url.AbsoluteUri and that's why I have the replace
:80 line.
USING THE .tochararray FUNCTION GIVES ME BACK THE INTRANETQA THING
myURL = myURL.Substring(6) gives back the intranetqa thing.
string.Contains("sar.smg.com.ar") gives back false.
I believe the trick lies around here:
Uri uriAddress1 = Request.Url; and "The parts are <br>" + "Part 1: " + uriAddress1.Segments[0] + "<br>Part 2: " + uriAddress1.Segments[1]; Gives Part1 : "/" and Part 2: "Default.aspx". Trying to access part 3 (index 2) gives an exception.
The request.url does not have the first part, but when I call the ToString() method, it does have like a "fake" first part
Between your browser and the server are a reverse proxy and an output re-writer. These may be the same component, or separate components.
The URL your server actually sees is always of the form http://intranetqa/default.aspx?tabid=912 (after the reverse proxy/URL re-writer has intercepted the request).
The output your server produces is actually like:
Copying it to myURL, it's now: "http://intranetqa/Default.aspx?TabID=912"
Trimming and ToLower myURL.
The new url is "http://intranetqa/default.aspx?tabid=912"
Replacing the ":80".
The new url is"http://intranetqa/default.aspx?tabid=912"
Replacing the "http://".
The new url is"intranetqa/default.aspx?tabid=912"
Removing everything after the "/".
The new url is "intranetqa"
GetPortalAlias Returning "intranetqa"
The output re-writer is inspecting the output from your server and doing a replace of http://intranetqa with http://sar.smg.com.ar. Once you strip the http:// off of the front of these strings, it's no longer a match and so replacement no longer occurs.
If you want to know what the original requesting URL/host are, hopefully the reverse proxy either is, or can be configured to, adding an extra header to the request with the original URL.
You can try something like this
Uri uriAddress1 = new Uri("http://www.contoso.com/title/index.htm");
Console.WriteLine("The parts are {0}, {1}, {2}", uriAddress1.Segments[0], uriAddress1.Segments[1], uriAddress1.Segments[2]);
Uri.Segments Property
This is better way to handle URIs and their segments.
Try to use this property instead:
String myURL2 = Request.Url.AbsoluteUri;
Here is an Extension method that I use to pull the SiteRootPath. You should be able to easily adjust it however you need it. You will need access to the HttpContext for what I currently have below, however, you don't sound like you need that.
using System;
using System.Web;
namespace FlixPicks.Web.Extensions
{
public static class HttpContextExtensions
{
public static string SiteRootPath(this HttpContext context)
{
if (context == null || context.Request == null) { return null; }
return context.Request.Url.SiteRootPath(context.Request.ApplicationPath);
}
public static string SiteRootPath(this HttpContextBase context)
{
return context.Request.Url.SiteRootPath(context.Request.ApplicationPath);
}
private static string SiteRootPath(this Uri url, string applicationPath)
{
if (url == null) { return null; }
// Formatting the fully qualified website url/name.
string appPath = string.Format(
"{0}://{1}{2}{3}",
url.Scheme,
url.Host,
url.Port == 80 ? string.Empty : ":" + url.Port,
applicationPath);
// Remove ending slash(es) if one or more exists to consistently return
// a path without an ending slash. Could have just as well choosen to always include an ending slash.
while (appPath.EndsWith("/") || appPath.EndsWith("\\"))
{
appPath = appPath.Substring(0, appPath.Length - 1);
}
return appPath;
}
}
}
Good luck,
Tom
Don't you want to achieve part of what is done here?
Something like
string host = Request.Url.IsDefaultPort ?
Request.Url.Host :
Request.Url.Authority;
If you want to persist with the old method change it like this
string GetPortalAlias()
{
var rawUrl = Request.Url.ToString();
var lowerTrimmedUrl = rawUrl.ToLower().Trim();
var withoutPortUrl = lowerTrimmedUrl.Replace(":80", "");
var withoutProtocolUrl = withoutPortUrl.Replace("http://", "");
var justHostUrl = withoutProtocolUrl.Remove(myURL.IndexOf("/"));
var evolution = new StringBuilder();
evolution.AppendFormat(
"{0}<br>",
HttpUtility.HtmlEncode(rawUrl));
evolution.AppendFormat(
"{0}<br>",
HttpUtility.HtmlEncode(lowerTrimmedUrl));
evolution.AppendFormat(
"{0}<br>",
HttpUtility.HtmlEncode(withoutPortUrl));
evolution.AppendFormat(
"{0}<br>",
HttpUtility.HtmlEncode(withoutProtocolUrl));
evolution.AppendFormat(
"{0}<br>",
HttpUtility.HtmlEncode(justHostUrl));
URLLabel.Text = evolution.ToString();
return justHostUrl;
}
So you can see whats going on.
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 + '¬eContent=' + noteText + '¬eId=' + 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.