I have a database with a row that has "TEXTTEXT" inside a "noteText" column and null in that column for a different row. If I run a query that generates 1 rows, then run a different query that has 2 rows, Eval("noteText") returns different information when placed in a TextBox vs. placed in a Label. The TextBox and Label were created specifically for this test; it is not referenced in the codebehind. I think the TextBox for row 1 of the second query is somewhow pulling the data used in row1 of the first query.
I don't think it could be a browser-related issue since the source code of the returned page is itself incorrect.
Aspx file code:
<asp:TemplateField HeaderText ="Notes" SortExpression="noteid">
<ItemTemplate>
STARTXX
<asp:TextBox ID="AtxtNote" ViewStateMode="Disabled" runat="server"
TextMode= "SingleLine" Width="260" Text='<%# Eval("noteText") %>' />
<br />
<asp:Label ID="BtxtNote" runat="server" Width="260"
Text='<%# Eval("noteText") %>' />
<br />
ENDXX
</ItemTemplate>
</asp:TemplateField>
Source code on page:
STARTXX
<input name="ctl00$CPH1$gv$ctl02$AtxtNote" type="text"
value="TEXTTEXT" id="ctl00_ContentPlaceHolder1_gv_ctl02_AtxtNote"
style="width:260px;" />
<br />
<span id="ctl00_CPH1_gv_ctl02_BtxtNote"
style="display:inline-block;width:260px;"></span><br />
ENDXX
Actual spacing is a bit different; I edited the text of the source and output code to prevent horizontal scrolling.
I expected both Eval calls to show an empty string.
We fixed it by adding more calls to DataBind.
The current theory is that the TextBox was being submitted when clicking the button to query the database. After the DataBind happened, Asp.Net repopulated the TextBox with the data that was submitted. The TextBox now logically corresponded to a different row in the database, but was in the same position as the TextBox from the previous page view and thus had the same ClientID.
One reason for this suspicion is that the posts were triggering OnTextChanged events.
I'm still unhappy with this; I don't have full confidence that I know what's going on, even though it is now working.
Related
in an old ASP.NET Web Forms application I got this warning in the aspx code of a page:
Attribute 'fullname' is not a valid attribute for element 'input'
Why was written in this way?
And there is a way to resolve it?
You only get a warning. The simple issue is that the developer just made up a attribute, and shoved in some value. this is legal, and I often do this for say a standard text box.
so, I might for example place 5 or 10 text boxes and controls inside of a div, say like this:
<div id="EditRecord" runat="server" style="float:left;display: normal;border:solid 2px;padding:5px">
<div style="float:left" class="iForm">
<label>HotelName</label>
<asp:TextBox ID="txtHotel" runat="server" f="HOtelName" width="280" /> <br />
<label>First Name</label>
<asp:TextBox ID="tFN" runat="server" f="FirstName" Width="140" /> <br />
<label>Last Name</label>
<asp:TextBox ID="tLN" runat="server" f="LastName" Width="140" /> <br />
<label>City</label>
<asp:TextBox ID="tCity" runat="server" f="City" Width="140" /> <br />
<label>Province</label><asp:TextBox ID="tProvince" runat="server" f="Province" Width="75"></asp:TextBox> <br />
</div>
etc. etc. etc.
Note in above, I wanted to define what data base column for a routine to "fill out" the above controls.
So, I have a routine I call with a data row.
Call fLoader(EditRecord, rstData.Rows(0))
the above routine looks for any control with a "f=datacolum", and fills out the controls for me.
So, I get this:
In other words, my custom "f" attribute allows me to pull data from a database, and fill out the web page - and without having to write new code each time. (and I have a reverse routine - writes out all controls with f="some data column" back to the database. With this simple concept, then I am able to have any web page read/write data to/from the database - and not have to write that same code over and over. In effect, I get a whole crud system, and all achieved by a simple concept of adding a "made up" attribute "f" that defines the data base column to use.
So, you can in VS have that warning suppressed, but I as noted OFTEN make and add some custom values. Even for a button in a grid view, you might have this:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Button ID="cmdView" runat="server" Text="Button"
OnClick="cmdView_Click"
ProductID = '<%# Eval("ProductID") %>'
CustomerID = '<%# Eval("CustomerID") %>'
/>
And then in code behind, you have this:
Protected Sub cmdView_Click(sender As Object, e As EventArgs)
Dim btn As Button = sender
Debug.Print(btn.Attributes("CustomerID").ToString())
Debug.Print(btn.Attributes("ProductID").ToString())
So, we often just make up some attribute, and it is legal to do so in most cases.
So, that button - say dropped into a grid view now can pass values to the button click - even values not displayed in the gridview.
So, you can just as a general rule ignore the warning. It is not super common, but a lot of developers often will add and make up their own attributes, and client side code (JavaScript) or even code behind as above shows is then free to use the values in those custom, or "made up" attributes. In most cases, you get a warning, but other then that, it not a huge deal nor issue. You of course do have to be carful, since such custom attributes in most cases don't have automatic view state, and their values will not persist correctly for a round trip (post-back, and page return). However, for expressions or values such as above example, then its not a problem.
I am making some changes to an internal application that has a Telerik RadGrid component on one .aspx page.
Each row in the RadGrid represents an order and there is a dropdown which allows setting the status of the order. Changing the status of the order updates a couple of other properties of the order which are displayed on that row.
Up until now, changing the order status has resulted in a complete page post back and re-render. I'm keen to change this to a partial post back using an UpdatePanel. I could wrap the status dropdown (a RadCombo) in an UpdatePanel which would take care of the actual database changes that are required (as per the code sample below), but then without updating the other properties on the RadGrid row, the updates are not presented to the user.
<telerik:RadGrid ID="OrdersGrid" runat="server" ...>
<MasterTableView DataKeyNames="OrderId" AllowMultiColumnSorting="false">
<NoRecordsTemplate ...></NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn ... />
...
<telerik:GridTemplateColumn HeaderText="Order Status" UniqueName="OrderStatus">
<ItemTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<telerik:RadComboBox ID="RadOrderStatus" DataSourceID="OrderStatusDataSource" runat="server"
SelectedValue='<%# Bind("OrderStatus") %>' Skin="Metro" Width="180px" DataTextField="OrderStatus"
DataValueField="OrderStatus" AutoPostBack="True" EnableLoadOnDemand="False" OnSelectedIndexChanged="RadOrderStatus_SelectedIndexChanged">
</telerik:RadComboBox>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<SortExpressions>...</SortExpressions>
</MasterTableView>
</telerik:RadGrid>
I'm wondering how I can use the UpdatePanel to effectively wrap the row of the RadGrid so that the entire row can be updated as opposed to just the cell that the dropdown is in. I've tried experimenting already with tag placement but I'm new to Telerik and therefore not very clued up.
At what level in the mark up can I place the UpdatePanel to get this to work as I'd like?
Or is there a Telerik way of doing this?
I could wrap the whole grid but if possible, I'd rather not have the whole grid update on each partial post back, the permitted operations are limited to the row level so I see a full grid update as wasteful.
You can't place an UpdatePanel around each row. For starters, there is no provision to do that (you can't do it with the standard GridView either). Then, if you manage to do that (e.g., override the Render event), you would get invalid markup because you can't have <div> elements inside the <table> and between the other <tr> nodes.
One note on the performance—the AJAX request will have the page go through its entire lifecycle on the server, so all code will be executed again and any time consuming operation will also be executed. The only difference between the AJAX and the full postback is what gets rendered and returned in the response, so you basically shave off network time only.
What you can do is the following:
wrap the entire grid. I would use RadAjaxPanel and RadAjaxLoadingPanel so you have a pretty loading indicator. Something like:
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Black"></telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<telerik:RadGrid ID="RadGrid1" runat="server"></telerik:RadGrid>
</telerik:RadAjaxPanel>
OR, use client-side code and jQuery. The combo can call a WebService or a PageMethod that will return the data and you can use jQuery to traverse the DOM and update the other elements (textboxes, dropdowns, whatever you have). This is going to be more difficult.
I need to insert a column with hidden field in grid view.
The user should not know that one column is there.
I tried the following: created a css class width display:none; and assigned ItemStyle-CssClass="MyCssClass".
But result is not satisfactory.
Inserted a template field and in itemtemplate I had given a asp:HiddenField
Both method shows an extra column hidden field.
There is no value since the fields are rendered as hidden fields but that column have width nearly 10 pixels (see this image http://www.tiikoni.com/tis/view/?id=c500726). So the user feels an empty row is there.
I need to completely hide the column.
I cannot use template field with visibility=false, because I need to access its value from client side.
You can keep the hidden field in your any column. And get it's value from anywhere you live.
Here is a good link to call value from the server side
access hidden field within gridview control to set a value in javascript?
Edit 1
Add a column as follows:
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lbl1" runat="server"
Value='<%# Eval("Name") %>' />
<asp:HiddenField ID="HiddenField1" runat="server"
Value='<%# Eval("BirthDate") %>' />
</ItemTemplate>
</asp:TemplateField>
And you can get the values of your hidden field easily.
I want to keep TextBox attribute Read Only in web form. But when I keep this Read Only , On PostBackits values get vanishes and I get empty text. How can I achieve the same functionality without loosing TextBox values.
You can achieve this by preventing user to enter values in the textbox, thus add following attributes to the textbox. It will maintain values even on postback also.
onkeypress="return false;"
Change it by removing the ReadOnly=”true” from the tag , we will add it in the code.
Now in the code add the following :
TextBox1.Attributes.Add(“readonly”, “readonly”);
You probably have it like this right now:
<asp:TextBox ID="MyTextBox" runat="server" Enabled="false" />
Just change this to:
<asp:TextBox ID="MyTextBox" runat="server" ReadOnly="true" />
And it will send its value over postback like all other form elements while still being read only.
I have a ASP.Net GridView and I build the column collection myself. Within the column collection I have a HeaderTemplate and within there I have a textbox which I use to filter the records in the grid.
When I enter text within this textbox and perform an action on the grid which causes a postback (i.e. changing the page) I lose the text within my textbox.
Anybody got any ideas as to why this data is lost?
My ASP code for the header template is below:
<HeaderTemplate>
<asp:Label ID="Label1" Text="Number" runat="server" />
<asp:TextBox ID="textBoxNumberFilter" runat="server" />
<asp:ImageButton ID="buttonFilterNumber" runat="server" OnClick="buttonFilters_Click" />
</HeaderTemplate>
Thanks in advance. I'm using ASP.Net 4.0
I think this might help.
http://www.codeproject.com/Articles/38714/How-To-Perpetuate-Dynamic-Controls-Between-Page-Vi