I am using the following code to update a listbox, this recieving a list from a Web service:
client.userKeywordsCompleted += new EventHandler<userKeywordsCompletedEventArgs>(client_userKeywordsCompleted);
client.userKeywordsAsync();
Using:
void client_userKeywordsCompleted(object sender, userKeywordsCompletedEventArgs e)
{
string result = System.Convert.ToString(e.Result);
for (int i = 0; i < e.Result.Count; i++)
{
ListBoxItem lbitem = new ListBoxItem();
lbitem.Name = "lb_" + i;
lbitem.Content = e.Result[i];
lbitem.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(ListBoxItem_DoubleClickEvent), true);
listBox1.Items.Add(lbitem);
}
This works fine, as I use it when the Child window loads, so the ListBox gets the list from the database, however, when a user selects one of the items in the ListBox, they have the option to edit the selected item. So once the edit is in place, there is an edit button, which updates the column in the table in the database. So then on the button click, I am again calling the aforementioned code to update the ListBox with the new credentials. However, this brings back the error:
"Value does not fall within the expected range."
Why can I not call the Web method on the button click, as all it is doing is refreshing the ListBox?
This might be due to the fact that you are trying to add a ListBoxItem with the same name to the page.
If you want to refresh the content of the listbox with the newly retrieved values you will have to first manually remove the content of the listbox other wise your loop will try to create lb_1 again and add it to the same list.
Look here for a similar problem that occurred Silverlight: Value does not fall within the expected range exception
I had from a totaly different reason the same notice "Value does not fall within the expected range" from the Visual studio 2008 while trying to use the:
Tools -> Windows Embedded Silverlight Tools -> Update Silverlight For Windows Embedded Project.
After spending many ohurs I found out that the problem was that there wasn't a resource file and the update tool looks for the .RC file
Therefor the solution is to add to the resource folder a .RC file and than it works perfectly.
I hope it will help someone out there
In case of WSS 3.0 recently I experienced same issue. It was because of column that was accessed from code was not present in the wss list.
Related
I have an aspx page of images that, when selected, a popup appears prompting for various information tid bits that I then store the information as data attributes on hidden labels through use of jQuery (i.e. data-id="####", data-difficulty="###", etc.). I acknowledge that this isn't the best way to do it necessarily but I've tried other things (see below) and nothing has worked yet.
I've been attempting, and to no avail, to retrieve the dynamically updated data attributes so the various items can be stored to my local ms sql database. The updating of the attributes works perfectly in that I can view the items being updated properly in Chrome's developer tools. Despite this when I try to pull the same attributes I can see as being updated I'm unable to retrieve the updated values in the code behind and keep getting back the initial values (generally an empty string "").
Here's the implementation on the aspx page:
<asp:Label runat="server" ID="lblSelection" data-id="" data-count="" data-price="" data-difficulty="" CssClass="selected-items" />
and here's the relevant method being called when the "Submit" button is clicked further down on the same page:
protected void SubmitClicked(object sender, EventArgs e)
{
var currentID = lblSelection.Attributes["data-id"];
var currentCount = lblSelection.Attributes["data-count"];
var currentPrice = lblSelection.Attributes["data-price"];
var currentDifficulty = lblSelection.Attributes["data-difficulty"];
if (currentID == null || currentID == "")
{
// stop and throw an informative message to the user
}else{
// keep processing ...
}
}
The trouble is that when I run the project in debug mode and inspect those elements (again, making sure that I can visually see that the attributes are actually updated in the developer tools) they're all the initial value of "". My only guess is that there's some kind of post back issue but I wouldn't think that would happen until my method had been called and fully processed. As a note, I'm populating the images onto the page and updating their attributes already through a sql call based on the id of the item:
<img runat="server" src="" data-id="12345" />
The initial loading all works perfectly so I can clearly set the properties from the code behind fine. For whatever reason though I am unable to pick up the updated attribute values in the code behind after the jQuery updates the label's attributes (following some clicking and whatnot). Any tips or thoughts on this would be greatly appreciated.
What you are trying to do cannot work because:
The value of custom attributes is not posted back to the server (as discussed here).
Even if you set the text of the Label in client code, it would also not be available in the Text property in code-behind. A Label is rendered as a span element in the page, and the content of that type of element is not posted back to the server.
A nice list of properties included in a postback is given in this topic: Which values browser collects as a postback data?
As suggested by mshsayem, you should use HiddenFields. If, for some reason, you want to do it differently, you could use hidden TextBoxes, set their value in client code, and retrieve it with the Text property in code-behind. In other words: HiddenFields are not the only controls for which a value set in client-code can be retrieved in code-behind (but they are the obvious choice if the control is not to be displayed).
I am developing an app using Xamarin.iOS in C# language. My tableview retrieves list from webservice. This list contains folders and files. and folders can have also children and maybe children also have their own children..
So to display files, I use webview, its OK but for folders, what should I do? There can be many subfolders, I am thinking to use 2 tableviews and one webview
First tableview is for showing first list
Second tableview will show the folder's content, can be some subfolders and files. If the file tapped, webview will display it, if folder tapped, then I should reload the list of tablewView..
Logically its OK but what about if user push back.. How I should get back previous list, I dont want to call it from webservice again.. I am asking what can be the best model for it?
I think nobody will not reply my question. Well I would like to share my solution..
I called the tableview in the same tablewView. First of All, I entered a storyboard id for the tableview controller name is commonstoryboard so after my code is like that
var item = (profileLists[indexPath.Row] as QuickSearchProfile);
var result = search.GetQuickSearchProfile(item);
// FillTable(result);
// TableView.ReloadData();
var controller = (CommonTableView)this.Storyboard.InstantiateViewController("commonstoryboard");
var commonTableView = new CommonTableView(controller.Handle);
commonTableView.profileLists.AddRange(result);
NavigationController.PushViewController(commonTableView, true);
so everything works how i want. I can go many subfolders and can back (previous views still have the old values, so in this case,i do not need to call again any list from web service) I really didnt expect that kind of solution but it became perfect !!
I have a site that is using the aspdotnetstorefront platform, although this should pertain to any C# site. There is a custom control in a dll named Account. This has several elements including text boxes for customers to enter name, phone number etc.
I have checked the source code with DotPeek and verified I am using the correct naming conventions.
I am attempting to use the javascript onChange event to copy the first name, last name and phone number to lower boxes when a check box (account information same as billing) is checked. So that if customers select that the information is the same it will be automatically copied as they move from one box to the next.
The odd thing is, this works with some of the text boxes but not others. To make things simple I have removed the JS that copies the contents and replaced it with a pop up box for testing.
This works, when I change the text I get a "Hello World" pop up box:
ctrlAccount.txtFirstName.Attributes.Add("onchange", "alert('hello,world')");
But this does not:
ctrlAccount.txtPhone.Attributes.Add("onchange", "alert('hello,world')");
The error I get is:
CS1061: 'AspDotNetStorefrontControls.Account' does not contain a definition for 'txtPhone' and no extension method 'txtPhone'
accepting a first argument of type
'AspDotNetStorefrontControls.Account' could be found
So it looks like the compiler cannot recognize the phone text box. When I look at the rendered page code (When the error has been removed of course) the box is there and the ID is correct.
Reading the source code with DotPeek I see:
public Account()
{
this._txtFirstName = new TextBox();
this._txtLastName = new TextBox();
this._txtEmail = new TextBox();
this._txtPassword = new TextBox();
this._txtPasswordConfirm = new TextBox();
this._txtPhone = new TextBox();
}
private void AssignClientReferenceID()
{
this._txtFirstName.ID = "txtFirstName";
this._txtLastName.ID = "txtLastName";
this._txtEmail.ID = "txtEmail";
this._txtPassword.ID = "txtPassword";
this._txtPasswordConfirm.ID = "txtPasswordConfirm";
this._txtPhone.ID = "txtPhone";
}
(I've removed a bunch of other fields in the interest of readability). But that certainly looks to me like text box for the phone number should have the idea of "txtPhone" and "txtFirstName" and "txtLastName" work just fine, so why would this fail on only the Phone box?
The code you've added to the question show only assignment of IDs and nothing else. I can't see the entire source code of Account control but usually fields with leading underscore are protected or private and, to expose these fields, public properties are used so please check if it's present a public property named txtPhone.
EDIT
ctrlAccount.txtFirstName.Attributes.Add("onchange", "alert('hello,world')");
ctrlAccount.txtPhone.Attributes.Add("onchange", "alert('hello,world')");
Try to press F12 with the caret over txtFirstName or txtPhone on the lines above to see where these property are defined.
P.S.:
Do not confuse the names of id and public properties of a class
It's VS bug, simple restart should help you.
Right-click the txtFirstName part and choose "Go to definition". Ensure that the txtPhone property is defined nearby and is accessible.
If you open your project on visual studio, you can right click on txtPhone or txtFirstName and click on "Go to definition". It will take you to the place where it is defined. Maybe txtFirstName is being read from somewhere else where txtPhone does't exist.
I get these kind of warning(not an error) on my application sometimes in compiler however on run time, it recognise the definition and no problem is caused.
I'm writing code to read data from asp controls to update records in a database. I've been debugging the last day and I've tracked it back to something that I ought to have noticed before.
The code first populates the controls with the existing values from the database.
When I click SAVE, it should read the current values from the controls and save with those.
Unfortunately, what it's actually doing is using the values of the controls before a change was made to them. It's not seeing the change to the controls.
Here's a sample:
<asp:TextBox ID="OtherCourseName_5" runat="server"></asp:TextBox>
Here's the corresponding behind code in the btnSave_onClick() function:
int object_number=5;
string other_course_name_string
= "OtherCourseName_" + object_number.ToString().Trim();
TextBox ocn = utilities
.utils
.FindControlRecursive(this.Master, other_course_name_string) as TextBox;
I'm using the FindControlRecursive() I found somewhere on the web. It works, I'm sure, but just in case, I tried to address the control directly as OtherCourseName_5.Text.
Even if I just display the value in OtherCourseName_5.Text, it gives the original value.
I use this same page for both entering new data and for editing data. It works fine when I enter the data. That is, it correctly sees that the TextBox control has changed from empty to having data. It's only when I invoke the edit function on the page (by passing edit=true). I invoke it this way by adding the switch edit=true as a query string (the program correctly reads that switch, gets to the appropriate area of code, prints out all the correct values for everything - except the contents of the controls!).
The page is far too complicated to post the entire thing. I've tried to convey the essential details. It's entirely possible that I've made a simple coding error, but it's seeming more a possibility that I fundamentally misunderstand how pages are processed.
Is there anything known that can make it seem as though the value of a control has not been changed?
Note 1: I thought perhaps I had to go to another field after I entered the data, but I tried that and it's still a problem.
Note 2: I'm using both TextBox and DropDownList controls and have the same problem with both.
Note 3: These controls are on a panel and the page is using a SiteMaster. I haven't had any problem with that and don't think the problem is there, but I'm down to questioning the laws of the physics at this point.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//populate controls with data from database
}
}
When you do a postback before the postback handler is evaluated the PageLoad event is raised
so if you don't avoid to rebind your control they will be loaded with the values from the database. And then the postback event will save them to db
Asp.net Page Lifecycle
(source: microsoft.com)
I have got an ASP-Site, which enables the user to Add Label-Elements. I don’t know how many Labels where added or which ID they have. I know only, they will be within the Panel pnl_Added. After the user has added all his labels, he pushes a Send-Button for Update.
So, now I am at my Server, awaiting this postback, but I don’t know where, when and how to find out, which Elements were Added to pnl_Added. Can somebody help me?
I have tried something like that:
protected void Page_Load(object sender, EventArgs e)
{
[...]
for (int i = 0; i < pnl_Added.Controls.Count; i++)
{
[...]
}
[...]
}
But I think it is too late because of the loaded ViewState? Is that possible?
I am working with VS 2013, ASP c#, with the .Net Framework 4.
On server, controls tree doesn't created from actual client HTML. Actually, server doesn't know anything about client HTML besides input tags values in scope of submitted form. In general, all controls available in Page_Load method, created on server side from aspx file markup.
To implement your scenario, you need to add hidden field for each label, added from client and save label's inner text into hidden field's value. Then you'll can get these labels texts as below:
var labels = Request.Form["hiddenField's name"] as string[];
You should go one lever deeper and take the added elements from Request variable, because the control pnl_Added doesn't know about them as there was no postback.
Something like this:
Request.Form["field_id"]
I suggest to run the page in debug mode, review Request.Form collection and find what you need. You should see your label elements there.