By saturation - Wed 23 Mar 2011
|
I have a form/.NET page that is able to makes inserts into the database, but for some reason, if I set the default form view to edit mode and hard-code an ID in my SelectCommand, the form does not show at all (even though the query returns records in SQL). If I set DefaultMode back to Insert, it shows again. Is there something in the compiled code that prevents this form from being shown in edit mode? My code is below:
<%@ page title="" language="VB" masterpagefile="~/MasterPages/Kartris.master" autoeventwireup="false" inherits="contact, KartrisCompiled" enableEventValidation="false" viewStateEncryptionMode="Always" %>
<asp:Content ID="cntMain" ContentPlaceHolderID="cntMain" runat="Server">
<div id="contact"> <div class="breadcrumbtrail"> <asp:SiteMapPath ID="smpTrail2" PathSeparator="<% $Resources: Kartris, ContentText_BreadcrumbSeparator %>" runat="server" SiteMapProvider="BreadCrumbSiteMap" /> </div> <h1> <asp:Literal ID="litPageTitleContactUs" runat="server" Text="<%$ Resources: Kartris, PageTitle_LoanApplication %>" /> </h1> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KartrisSQLConnection %>" SelectCommand="SELECT dcca_applicantid,dcca_firstname FROM tblDCCreditApplication WHERE dcca_applicantid=1" UpdateCommand="UPDATE tblDCCreditApplication SET dcca_firstname=@dcca_firstname" InsertCommand="EXEC spDCUsers_AddUserAddressCreditApp @dcca_firstname"> <SelectParameters> <asp arameter Name="dcca_applicantid" Type="String" /> <asp arameter Name="dcca_firstname" Type="String" /> </SelectParameters> <UpdateParameters> <asp arameter Name="dcca_applicantid" Type="String" /> <asp arameter Name="dcca_firstname" Type="String" /> </UpdateParameters> <InsertParameters> <asp arameter Name="dcca_firstname" Type="String" /> </InsertParameters> </asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceId="SqlDataSource1" DataKeyNames="dcca_applicantid" DefaultMode="Edit" > <InsertItemTemplate> <h3>Applicant Info:</h3> <span class="Kartris-DetailsView-Name">First Name:</span><span class="Kartris-DetailsView-Value"><asp:TextBox ID="dcca_firstname" runat="server" Text='<%# Bind("dcca_firstname") %>'></asp:TextBox></span><br /> <div class="submitbuttons"> <asp:Button CssClass="button" ID="butSubmit" runat="server" CommandName="Insert" Text="<%$ Resources: Kartris, FormButton_Submit %>" /> </div> </InsertItemTemplate>
<EditItemTemplate> <h3>Applicant Info:</h3> <span class="Kartris-DetailsView-Name">First Name:</span><span class="Kartris-DetailsView-Value"><asp:TextBox ID="dcca_firstname" runat="server" Text='<%# Bind("dcca_firstname") %>'></asp:TextBox></span><br /> <div class="submitbuttons"> <asp:Button CssClass="button" ID="butSubmit" runat="server" CommandName="Edit" Text="<%$ Resources: Kartris, FormButton_Submit %>" /> </div> </EditItemTemplate> </asp:FormView> </div> </asp:Content>
|
By Mohammad - Wed 23 Mar 2011
|
Nothing in the compiled code prevents something like this.
Try changing the "AutoEventWireup" attribute in the page directive to true instead of false.
|
By saturation - Wed 23 Mar 2011
|
Thanks, Mohammad--but even if I strip everything out but the EditItemTemplate and hard-code some text, it still does not render it. Ideas?
<%@ page title="" language="VB" masterpagefile="~/MasterPages/Kartris.master" autoeventwireup="true" inherits="contact, KartrisCompiled" enableEventValidation="false" viewStateEncryptionMode="Always" %>
<asp:Content ID="cntMain" ContentPlaceHolderID="cntMain" runat="Server">
<div id="contact"> <div class="breadcrumbtrail"> <asp:SiteMapPath ID="smpTrail2" PathSeparator="<% $Resources: Kartris, ContentText_BreadcrumbSeparator %>" runat="server" SiteMapProvider="BreadCrumbSiteMap" /> </div> <h1> <asp:Literal ID="litPageTitleContactUs" runat="server" Text="<%$ Resources: Kartris, PageTitle_LoanApplication %>" /> </h1> <asp:label id="HelloWorld" runat="server" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:KartrisSQLConnection %>" > </asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceId="SqlDataSource1" DataKeyNames="dcca_applicantid" EmptyDataText="NO DATA" DefaultMode="Edit" EnableViewState="true" > <EditItemTemplate>
Some Test TEXT!!! <h3>Applicant Info:</h3>
</EditItemTemplate> </asp:FormView> </div> </asp:Content>
|
By Paul - Fri 25 Mar 2011
|
When you view the source of the page, does the section show up there? I'm curious whether by 'not rendering' it is because the HTML itself is not generated, or because for some reason the browser is not displaying it.
|
By saturation - Fri 25 Mar 2011
|
I did View > Source and searched for "Some Test" and it doesn't seem to be even putting the text in the page. What I cannot figure out is why the InsertItemTemplate will render the controls while the EditItemTemplate does not? It's like it doesn't even recognize the EditItemTemplate tags.
|
By Mohammad - Fri 25 Mar 2011
|
In the FormView control, if the select statement returns 0 records the whole EditItemTemplate will not be rendered in the page, also if you don't have at least 1 input control in the EditItemTemplate the same story will happen; the template will not be rendered.
In your second post : <EditItemTemplate> Some Test TEXT!!! <h3>Applicant Info:</h3> </EditItemTemplate> will never rendered in the page, cause it doesn't have any input control (text box, dropdown ..etc)
The InsertItemTemplate will not be rendered also if you don't have at least 1 input control.
So, all what I could think about is to make sure the select command will return at least 1 record and make sure to have at least 1 input control in the Insert/Edit ItemTemplate(s) - just like the 1st post.
|
By saturation - Sat 26 Mar 2011
|
Wow, thank you guys. I broke it down even further after your suggestions Mohammad and Paul....Turns out I didn't have the "[" and "]" around my SQL fields. Now I feel like a fool!
|