.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
" yc=""><tr>
"><td> <strong> Gender: </ strong> </ td>
Post New Web Links

FormView clearing value I set in page_load.

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :ASP.Net
I have a page with a FormView on it. The page is strictly for adding records to a Table. I have the FormView bound to an EntityDataSource and everything works greate except for one thing. I want to initialize a date field in the FormView to today's date. So, in my page_load event I have:               if (!Page.IsPostBack)            {                //Initialize SetupDate to today.                TextBox setupdate = (TextBox)fvJob.FindControl("txtSetupDate");                setupdate.Text = DateTime.Now.ToShortDateString();            } The first time this page loads, the txtSetupDate field is initialized. Although, and subsequent loads of the page doesn't initialize the Text Box. I step through the code in the debugger and I can see that the code is executig, but something (the FormView bind?) is "clearing" the Text Box. Any ideas? Why does it work on the first load, but not subsequent ones? Thanks for any help!  

View Complete Post

More Related Resource Links

How to fill a formview at page_load?

I have a formview and I want to fill it at page_load. The formview must show the data of the person that has logged in.So the question is how can I fill the formview so that is shows the data of the right person (UserId = @Param2) so that the formview is in editmode?This is the code for the Formview:<asp:FormView ID="FormView1" runat="server" DataKeyNames="UserId" DataSourceID="MySQLProfielDataSource"> <ItemTemplate> <asp:Table id="ItemTabel" runat="server"> <asp:TableRow> <asp:TableCell> UserId: </asp:TableCell> <asp:TableCell> <asp:Label ID="UserIdLabel" runat="server" Visible="false" Text='<%# Eval("UserId") %>' /> </asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell> Geslacht: </asp:TableCell> <asp:TableCell> <asp:Label ID="Gesla

Formview LinqData source not allowing updates


OK, I'm confused.  I've set up a formview with a Linqdata source to allow users to edit records.  When I run it, edit data and submit, it blows up and tells me "Linq datasource6  does not support the Select property when the Delete, Insert or Update operations are enabled."  I googled that warning and saw a couple of posts on this forum saying the problem is the slect statement has to be removed from the Linq data source for it to allow updates. 

But if I remove the select statement then how do I show the user specific info on pageload?   plus I thought the two way databind was an advantge of the datasource control.




FormView -- Parameters and asp:Table


I've already solved this problem to my satisfaction, I just want to know WHY it works this way.

I have a FormView control bound to an ObjectDataSource.  Let's say our data source is a hypothetical table with three columns:  id, name, age.  Why is it that when I use the <asp:Table> element inside of the FormView, the parameter values are not set, but when I use the standard <table> tag, it works fine?

This seems like a .NET problem to me.  I expect the <asp:Table> element to work in the same way as <table> because they are, for all intents and purposes, the same thing.  Am I missing something?

DropDownList within FormView Error

I have a FormView which works find and I have added a new DropDownList within the form which references another table to which I need to select a value,
I have added the dropdownlist2 and setup a new connection string to this, when I run the page I get this error:

Could not find control 'DropDownList2' in ControlParameter 'CurrencyID'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Could not find control 'DropDownList2' in ControlParameter 'CurrencyID'.
any help would be greatly

Help ~~ How to Update Binary Image on Formview

Hi All ~~ I'm confused, Can i have some help please... Thanks
Database: Books
uid dataType uniqueidentifier
Cover dataType image 
aspx :
 <asp:FormView ID="FormView1" runat="server" BackColor="LightGoldenrodYellow"   BorderColor="Tan" BorderWidth="1px" CellPadding="2" DataKeyNames="uid"     DataSourceID="SqlDataSource1" ForeColor="Black" Width="525px">
         <table class="table_width">
                 <td class="imageWidth">
                     <asp:Image ID="Image1" runat="server" Height="245px" 
                                       ImageUrl='<%# IIF(Eval("Cover") Is DbNull.Value, "~/Styles/Global/CFZ-No-Images.png", Eval("uid", "~/ImageServices.ashx?BooksID={0}")) %>' Width="180px" />

Textbox not clearing on data add


Hi, I am new to ASP.Net development, trying to develo pa simple access based library system.

I am using panel to place a few textboxes and buttons on it, on page load, i open db conenction and bound textboxes to recordsets to show data (and navigate using first and previous buttons)

On add button I call a function to clear textboxes, so user can input data, then when i try to write the data back in DB it shows me textbox still showing old record from record set, means "textbox.text="" didn't work.

Any help or idea?


Help with displaying formview based on dropdownlist


I have a formview1 with a dropdownlist1 in the insert template. Based on the value of that dropdownlist I would like to display a second formview on the same page in insert mode so that I can write data to two different tables.

How can I accomplish this?

Is this the best way to do it?



FormView KeepInEditMode=true isn't retaining values


I have an "Edit Page" in my application. It uses a FormView bound to an EntityDataSource.

I have a handler setup for the FormView OnItemUpdated event. If an exception occurs (such as foreign key constraints or non date vales entered in a date colum, etc.), then I set the "KeepInEditMode=true". This is SUPPOSED to retain the user entered values on all of the text boxes instead of rebinding the FormView to the data again and clearing those text boxes. (Right?)

Well, it isn't working...

I have stepped through the code via the debugger and the "KeepInEditMode" does get set to true, but as soon as the page reloads, the values revert back to the original database values (the data is being rebound).

I should also mention that I am setting "ExceptionHandled" to true. I am doing this because I am handling the Exception by displaying an error in a specific area of the page and if I dont mark it as handled, IE generates an Exception popup.

Any ideas?

FormView Text Field Being Set by A Drop Down List


Hello, I have a FormView which is used to insert a record into a database.  Outside of this formview i have a drop down list, I want to grab the value from that drop down list and set one of the text fields within the formview to it's currently selected value.  I've tried the following code, but the dynamic categorytextbox line is what seems to not be working.

                    <asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="True" 
DataSourceID="SqlDataSourceCategory" DataTextField="CategoryName"
DataValueField="CategoryID" Width="200px">

                            <asp:TextBox ID="CategoryIDTextBox" runat="server" 
Text='<%# Bind("CategoryID") %>' Visible="False" />

        protected void FormView1_DataBound(object sender, EventArgs e)
dynamic varCategory = ddlCategory.SelectedValue;
dynamic categoryTextBox = FormView1.FindControl("CategoryIDText

Formview PagerTemplate DropDownList Navigation


Does anyone know if its possible to use a DropDownList within the PagerTemplate to navigate to a specific record?  I have been able to place the DropDownList outside of the FormView and PagerTemplate and make it work, however, I can't get it to work inside the PagerTemplate.


RadioButtonList in FormView EditTemplate's not me behind and OldValue NewValues


Hello people,

I am using FormView component which has a field that is the sex of the person that I am using RadioButtonList with a simple way to show Male and Female, but want to retrieve the information and OldValue NewValues not anything behind me.

In the FormView Edit Template:
" yc=""><! - SEX ->

Gender: " yc="Sexo:   " yc=""><td>
   'RepeatColumns = "2">     " yc="' RepeatColumns="2">"><Asp: RadioButtonList ID = "CHR_SEXORadioButtonList" runat = "server" SelectedValue ='<%# Eval ("CHR_SEXO")%> &#

Formview + EditItemTemplate + Bind + PageLoad + Prerender = Confused


I am working with a formview edititemtemplate.  Currently in my page load, i have some stuff that would show or hide certain panels based on dropdownlist values.  These dropdown values get binded during page load.  I need to be able to change the values/dropdowns, without rebinding the old data, and updating the visibility of the panels based on predefined rules.

I have experimented with putting my formview.databind() in page load if isnotpostback, in prerender, in prerender if isnotpostback.   I have tried my rules (ex if ddlState.selectedvalue = "DE" then pnlDelaware.visible = "true") in the page load, and the page render.   I'm just not sure how to get the stars aligned here.

The closest i have come is having the databind in the pageload if notispostback, and the rules in the prerender.   However I get an error "dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items.


CheckBoxList embedded in FormView InsertItemTemplate problem


I've searched hi/lo and found many similar posts but those answers aren't working for me.

I've got a FormView, in an UpdatePanel.  In the FormView's EditItemTemplate and InsertItemTemplate I'm using both a CheckBox and a CheckBoxList.  To present the data I databind in the code behind, (but then have to iterate to mark selected).  There I cast the sender as CheckBoxList in the OnPreRender event and use that object. 

The problem is retrieval.  I'm trying to access the user's entries when they submit by using the cast.  It is working fine for the CheckBox, but for the CheckBoxList the resulting checkboxlist object doesn't have any items. 

Here, both active and roles are created (they're not 'null') and active has the expected 'name' and 'selected' values, but roles has an item count = 0 and the for loop isn't entered.


            CheckBox active = ((CheckBox)Emp_Form.FindControl("cbActive"));

            CheckBoxList roles = (CheckBoxList)Emp_Form.FindControl("UsrRoles");

            foreach (ListItem role in roles.Items)
                // do stuff


Is there another way to cast a checkboxlist?  Any help would b

Unwanted form clearing

Hi all, Some users have somtetimes problem with unwanted reload and clearing form after they do some action. For instance they fill grid with some data then click "add another position" and form reload and lose its data. There is no rule cuz they can add 10 position and on 11 the error occur or even 100 and on 101 the error appear. The form looks as you click "CTRL + R" or go to it again through menu.  This is not only one form but generally it may appear on all forms. Any ideas what may cause this error? I am not sure if it is a WCF problem but on other apps I have't noticed such a problem.

Clearing WF instances?

Hi, I have been creating lot of WF instances, and now im running of memory after running the program for 15 min or so. Is there any way to clean up the resources in Workflow Application Completed method?

Page_Load Order -- Inserting a record

Is there any way to make sure an Insert Command happens before the Page_Load Events? I'm having a problem with inserting, then reading the DataSet directly after.  It seems it processes too quickly, or prior to the record being inserted. It has an impact on the DataSet that is to be displayed on screen. Summary:  Page_Loads > Finds Saved Data > If None exists (string contains 2 types of matches) > Displays the 1 of 2 types randomly. Buttons 1 & 2 Insert their respective options > Page Posts Back > Page_Loads > Read Saved Data > If my Max amount of the 1 of 2 types of Data are reached, the remaining type is shown > Displayed on page The problem I am having is that my DisplayDataSet is not getting the correct values.  It seems it's always 1 record behind on the count, because the count happens so fast, it's not getting the record that was just inserted. How can I write this, or make sure the "Find Saved Data' Routine happens after the Insert has been preformed?  Imports System.Data Imports System.Data.SqlClient Partial Public Class Assessment1 Inherits System.Web.UI.Page Protected Sub btnINS1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnINS1.Click Dim connetionString As String Dim connection As SqlConnection Dim adapter As New SqlDataAdapter Dim s

How do I show the last record added when using FormView?

hello all, I am using FormView to display one record at a time and after I add a new record, it won't display the last recorded added.How can I force FormView to display the last record added? Thank you  
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend