473,748 Members | 9,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Odd FormView behaviour on update

Hi

I have a PlaceHolder control inside a FormView EditItemTemplat e:

<asp:PlaceHolde r ID="phResponseT ext" runat="server">
<tr>
<td>
<asp:Label ID="lblResponse Text" runat="server"> </asp:Label></td>
<td>
<asp:TextBox ID="tbResponseT ext" runat="server" Text='<%#
Bind("ResponseT ext") %>'></asp:TextBox></td>
</tr>
</asp:PlaceHolder >

<asp:Button ID="btnUpdate" runat="server" CommandName="Up date"
Text="Publish" />

In the Page_Load event I run a routine which makes phResponseText. Visible =
false on each first page load and postbacks depending on the value of
another DropDownList. This works as expected when other controls are
AutoPostBack for example but when the FormView btnUpdate is clicked the page
is postback and the phResponseText PlaceHolderer is displayed as in the
declarative state but completely ignores the programmatic property settings
in Page_Load. I've run a trace on the Visible property in both the Page_Load
and Page_PreRender events and the Visible property shows as false. Can
someone tell me what can possibly be wrong?

Thanks
Andrew
Jan 30 '07 #1
3 3641
Hello Andrew,

From your description, you're putting a placeholder control in FromView's
EditTemplate, and you'll programmaticall y determine the placeholder's
Visibility according to another dropdownlist's selected item. However, you
found that the placeholder's visiblity doesn't be as expected when you try
perform updating on the Formview, correct?

As for this problem, I still have something need to confirm on your page:

1. Whether the dropdownlist is in FormView or ouside the Formview, but on
the same page.

2. How did you programmaticall y set the DropDownList's Visibilty and in
which event (page or FormView's) did you put the code

3. When you click update button(or postback the page to trigger FormView's
update command), the formView should return back to readonly mode after the
postback. When did you check the visibility? Do you mean you check in the
updating event(or any other event during the update comand postback)?

I've created a test page on my side based on my understanding. And I put
the programamtic visibility code(for the placeholder) in FormView's Load
event. You can refer to it and let me know if there is anything I missed.
===========aspx =============== ==
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownLi st ID="DropDownLis t1" runat="server">
<asp:ListItem>a aa</asp:ListItem>
<asp:ListItem>b bb</asp:ListItem>
<asp:ListItem>c cc</asp:ListItem>
<asp:ListItem>d dd</asp:ListItem>
</asp:DropDownLis t><br />
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="A ddressTypeID" DataSourceID="S qlDataSource1"
OnItemCreated=" FormView1_ItemC reated"
OnItemUpdating= "FormView1_Item Updating" OnLoad="FormVie w1_Load"
OnModeChanged=" FormView1_ModeC hanged">
<EditItemTempla te>
AddressTypeID:
<asp:Label ID="AddressType IDLabel1" runat="server"
Text='<%# Eval("AddressTy peID") %>'></asp:Label><br />
Name:
<asp:TextBox ID="NameTextBox " runat="server" Text='<%#
Bind("Name") %>'></asp:TextBox><br />
<hr />
&nbsp;

<asp:PlaceHolde r ID="PlaceHolder 1" runat="server">
<table>
<tr>
<td>
<asp:Label ID="lblResponse Text"
runat="server"> Response Text: </asp:Label></td>
<td>
<asp:TextBox ID="tbResponseT ext"
runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</td>
</tr>
</table>
</asp:PlaceHolder >
<br />
<hr />
<br />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update"></asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel"></asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
Name:
<asp:TextBox ID="NameTextBox " runat="server" Text='<%#
Bind("Name") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
AddressTypeID:
<asp:Label ID="AddressType IDLabel" runat="server" Text='<%#
Eval("AddressTy peID") %>'></asp:Label><br />
Name:
<asp:Label ID="NameLabel" runat="server" Text='<%#
Bind("Name") %>'></asp:Label><br />
<asp:LinkButt on ID="EditButton " runat="server"
CausesValidatio n="False" CommandName="Ed it"
Text="Edit"></asp:LinkButton>
</ItemTemplate>
</asp:FormView>

</div>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:AdventureWor ksConnectionStr ing %>"
SelectCommand=" SELECT AddressTypeID, Name FROM
Person.AddressT ype" UpdateCommand=" UPDATE Person.AddressT ype SET">
</asp:SqlDataSour ce>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>

=========code behind========= ====
public partial class FormViewPage : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{

}
protected void FormView1_ItemC reated(object sender, EventArgs e)
{

}
protected void FormView1_ModeC hanged(object sender, EventArgs e)
{

}
protected void FormView1_Load( object sender, EventArgs e)
{
Response.Write( "<br/>FormView1_Load +FormView1_Curr entMode: " +
FormView1.Curre ntMode);

if (FormView1.Curr entMode == FormViewMode.Ed it)
{
if (DropDownList1. SelectedValue == "ccc")
{
FormView1.FindC ontrol("PlaceHo lder1").Visible = true;
}
else
{
FormView1.FindC ontrol("PlaceHo lder1").Visible = false;
}

}
}
protected void FormView1_ItemU pdating(object sender,
FormViewUpdateE ventArgs e)
{
Response.Write( "<br/>FormView1_Item Updating+FormVi ew1_CurrentMode :
" + FormView1.Curre ntMode);

if (FormView1.Curr entMode == FormViewMode.Ed it)
{
if (DropDownList1. SelectedValue == "ccc")
{
Response.Write( "<br/>Visible: " +
FormView1.FindC ontrol("PlaceHo lder1").Visible );
}
}

e.Cancel = true;
}
}
=============== =============== ====

Hope this helps some. If there is any other questions, please feel free to
let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.


Jan 31 '07 #2
Hi Steven

Please see my answers between your text below.
From your description, you're putting a placeholder control in FromView's
EditTemplate, and you'll programmaticall y determine the placeholder's
Visibility according to another dropdownlist's selected item. However, you
found that the placeholder's visiblity doesn't be as expected when you try
perform updating on the Formview, correct?
This is correct.
1. Whether the dropdownlist is in FormView or ouside the Formview, but on
the same page.
The dropdownlist which determines the placeholder's visibility is inside the
FormView's EditTemplate too.
2. How did you programmaticall y set the DropDownList's Visibilty and in
which event (page or FormView's) did you put the code
I used the Page load event to start with but tried the FormViews Load event
too which gives the same result.
>
3. When you click update button(or postback the page to trigger FormView's
update command), the formView should return back to readonly mode after
the
postback. When did you check the visibility? Do you mean you check in the
updating event(or any other event during the update comand postback)?
when the update command is fired I want the page to save and reload in Edit
mode again. This is my FormView Load event

protected void fvPub_Load(obje ct sender, EventArgs e)
{
if (Int32.TryParse (Request.QueryS tring["PubID"], out _pubID) == false)

{

fvPub.DefaultMo de = FormViewMode.In sert;

}
if (_pubID != 0)
{
fvPub.DefaultMo de = FormViewMode.Ed it;
}

DropDownList ddlResponseType =
(DropDownList)f vPub.FindContro l("ddlResponseT ype");
phResponseText = (PlaceHolder)fv Pub.FindControl ("phResponseTex t");
//...
ResponseTypes respType = (ResponseTypes) Enum.Parse(type of(ResponseType s),
ddlResponseType .SelectedValue) ;
switch (respType)
{
case ResponseTypes.N one:
phResponseText. Visible = false;
break;
case ResponseTypes.U RL:
phResponseText. Visible = true;
//...break;
}
}

If I cancel the updating event then the page works as expected but obviously
i don't want to do that. I don't understand the purpose of this behaviour. I
want the user to be able to save changes to the page (like a windows form
'Apply' button) and then have the page reload back in edit mode.
protected void fvPub_ItemUpdat ing(object sender, FormViewUpdateE ventArgs e)

{

e.Cancel = true;

}
I've created a test page on my side based on my understanding. And I put
the programamtic visibility code(for the placeholder) in FormView's Load
event. You can refer to it and let me know if there is anything I missed.
You've understood everything I'm doing I think. Can you give me your
recommendations ?

Thank you.
Andrew

Feb 3 '07 #3
Hello Andrew,

After some further research, I think we may need to do some changes here.
Here are what I have got so far:

** If you want to make sure the visiblity of the nested placeholder
synchronous to the dropdownlist's selected value in all mode(no matter
whether the FormView has entered edit mode or not), I think you need to set
the DropDownList as "AutoPostback=t rue".

** Instead of using Load event, we should put the code which set the
Visiblity of nested placeholder(acc ording to dropdownlist's selected value)
in FormView's PreRender event. Since that's the last event we can change
its status, and at that time we can ensure that the DropDownlist.Se lected
Value(get at that time) is update to date

** To make the FormView still remain Edit mode after successfully update
the backend database, I think you can add a private page variable (as a
flag) to control the FormView's Mode. And you need to add code in
FormView's PreRender event to set its Mode according to this flag variable.

I have pasted my complete test page's aspx and codebehind below, you can
refer to it and get what I current use(the important part are all in
codebehind). If you feel necessary, I can also email the test pages to you.

==============a spx============ ===========

<form id="form1" runat="server">
<div>
<asp:DropDownLi st ID="DropDownLis t1" runat="server"
AutoPostBack="T rue">
<asp:ListItem>a aa</asp:ListItem>
<asp:ListItem>b bb</asp:ListItem>
<asp:ListItem>c cc</asp:ListItem>
</asp:DropDownLis t><br />
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:ASPNETTestDB ConnectionStrin g %>"
DeleteCommand=" DELETE FROM [RVTable] WHERE [id] = @id"
InsertCommand=" INSERT INTO [RVTable] ([name]) VALUES (@name)"
SelectCommand=" SELECT [name], [id] FROM [RVTable]"
UpdateCommand=" UPDATE [RVTable] SET [name] = @name WHERE [id] = @id">
<DeleteParamete rs>
<asp:Paramete r Name="id" Type="Int64" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="name" Type="String" />
<asp:Paramete r Name="id" Type="Int64" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="name" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
&nbsp;</div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="i d"
DataSourceID="S qlDataSource1" OnPreRender="Fo rmView1_PreRend er"
OnItemUpdated=" FormView1_ItemU pdated"
OnItemUpdating= "FormView1_Item Updating">
<EditItemTempla te>
name:
<asp:TextBox ID="nameTextBox " runat="server" Text='<%#
Bind("name") %>'>
</asp:TextBox><br />
id:
<asp:Label ID="idLabel1" runat="server" Text='<%#
Eval("id") %>'></asp:Label><br />
<asp:PlaceHolde r ID="PlaceHolder 1" runat="server">
<br /><hr /><br />
<asp:Label ID="Label1" runat="server" Text="Additiona l
Input"></asp:Label>
<asp:TextBox ID="txtInput" runat="server"> </asp:TextBox>
<br /><hr /><br />
</asp:PlaceHolder >
<br />
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date"
Text="Update">
</asp:LinkButton>
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplat e>
<InsertItemTemp late>
name:
<asp:TextBox ID="nameTextBox " runat="server" Text='<%#
Bind("name") %>'>
</asp:TextBox><br />
<asp:LinkButt on ID="InsertButto n" runat="server"
CausesValidatio n="True" CommandName="In sert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButt on ID="InsertCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTempl ate>
<ItemTemplate >
name:
<asp:Label ID="nameLabel" runat="server" Text='<%#
Bind("name") %>'></asp:Label><br />
id:
<asp:Label ID="idLabel" runat="server" Text='<%# Eval("id")
%>'></asp:Label><br />
<asp:LinkButt on ID="EditButton " runat="server"
CausesValidatio n="False" CommandName="Ed it"
Text="Edit">
</asp:LinkButton>
<asp:LinkButt on ID="DeleteButto n" runat="server"
CausesValidatio n="False" CommandName="De lete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButt on ID="NewButton" runat="server"
CausesValidatio n="False" CommandName="Ne w"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
</form>
=============== ==========

=========code behind========= ======
public partial class subdir_FormView Page : System.Web.UI.P age
{
private bool _setEdit = false;
protected void Page_Load(objec t sender, EventArgs e)
{

}
protected void FormView1_PreRe nder(object sender, EventArgs e)
{
if (_setEdit == true)
{
FormView1.Chang eMode(FormViewM ode.Edit);
}
if (FormView1.Curr entMode == FormViewMode.Ed it)
{
if (DropDownList1. SelectedValue == "ccc")
{
FormView1.FindC ontrol("PlaceHo lder1").Visible = true;
}
else
{
FormView1.FindC ontrol("PlaceHo lder1").Visible = false;
}

}
}
protected void FormView1_ItemU pdating(object sender,
FormViewUpdateE ventArgs e)
{
PlaceHolder holder = FormView1.FindC ontrol("PlaceHo lder1") as
PlaceHolder;
TextBox txtInput = holder.FindCont rol("txtInput") as TextBox;

if (holder.Visible == true && txtInput != null)
{
Response.Write( "<br/>additional input: " + txtInput.Text);
}
}
protected void FormView1_ItemU pdated(object sender,
FormViewUpdated EventArgs e)
{
_setEdit = true;

}
}

=============== =============

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
6205
by: Ottar | last post by:
I have a few numeric fields, and when I update i get the error: "Input string was not in a correct format". Next line:" System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2178925" This is beacuse some of my TextBoxes are empty (no value). If I enter a value it is OK. I need to use Null values to indicate that the field is not fileld in.
3
3879
by: Michael Glass | last post by:
I'm working on an ASP.Net web app using VS2005 and the .Net 2.0 framework, and I have a serious problem with the page I'm currently working on. The page has, among other things, two FormViews and a GridView control, each with its own SqlDataSource. FormView1 talks to my Opportunity table and has an ItemTemplate and an EditItemTemplate. FormView2 talks to my Activities table and has an ItemTemplate, InsertItemTemplate and an...
3
6043
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is "LabLocation_ID". With an existing lab, they then need to add the members for that lab. So, what I am trying to do is the following. With the FormView of the Lab open, the user will click a button to open a FormView (InsertMode) and add a new...
0
2207
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase .NET 2.0 DataProvider (iAnywhere.Data.AsaClient.dll) into the GAC so it can be used in the ProviderName property of a SQLDataSource and loads properly at run time. The application I'm writing is a bit more complex than the example I'm about to...
6
2086
by: Douglas J. Badin | last post by:
Earlier this month, there was a posting about this without a definitive answer. If you place a Wizard inside a FormView's EditItemTemplate the bound fields contained within the View will display the data from the fields to which they are bound; yet they will return null values when the 'Update' LinkButton is clicked. The responder thought this might have something to do with naming containers. If so, this is similar to an issue in...
3
3431
by: Jurgen Appelo | last post by:
I asked this question earlier, but unfortunately the two replies I got did not solve the problem. Here it is again, but now with the code: After an Update my FormView always loses its viewstate values. The field values in the FormView are always overwritten by the results of the Update method in the business layer. No matter what I do, the databind always takes place, even when I don't want it to. See the example below. This is a...
0
3579
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
0
1230
by: sanjeev06 | last post by:
When Updating using a FormView and ObjectDataSource, the formview always does the data-binding of its controls and the field values in the FormView are always overwritten by the results of the Update method. This behavior is fine when update method succeeds. But the problem is that when for some reason (e.g. a business rule "start date can not be prior to 1/1/2006") business layer rejects the data and Update method returns False (or...
3
8104
by: KaOne | last post by:
Hi All, excuse me in advance for my not very perfect english. I need some help about a problem with a FormView bounded to an ObjectDataSource. In practise I have an ObjectDataSource that uses some BLL methods that implements the optimistic concurrency by a TimeStamp field into the DB. So, when I execute an insert, update or delete query if I receive 0 like return value from that queries I understand that a concurrency problem is occurs so...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.