troubleshooting Question

ASP.NET Set a TextBox Equal to LoginName in a DetailsVIews Inside a LoginVIew

Avatar of lezloh
lezloh asked on
.NET ProgrammingASP.NET
12 Comments1 Solution1805 ViewsLast Modified:
All,

I am using C#, ASP.NET 2.0, Visual Web Developer 2005.

I have been trying for a while to set the value of a textbox (Person_Signing_Off) inside a DetailsView (DetailsView1) inside a LoginVIew(LoginView1) to the value of the LoginName(LoginName1). I keep getting a null exception error, which I believe to be because it can not find the TextBox inside the DetailsView. I have tried several fixes with no luck.

I am trying to set the Person_Signing_Off as the LogInName. My code has it just setting it to "test" right now. It errors out on the  "if (signer.Text == "")" in the code behind page.

Code Behind Page:

 protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        DetailsView myDetails = (DetailsView)LoginView1.FindControl("DetailsView1");

        TextBox signer = (TextBox)myDetails.FindControl("Person");
        if (signer.Text == "")
        {
            signer.Text = "test";
        }
        if (myDetails.CurrentMode == DetailsViewMode.Edit)
        {
            foreach (DetailsViewRow dvr in myDetails.Rows)
            {
                if (dvr.Cells.Count.Equals(2) && dvr.Cells[1].HasControls())
                {
                    Control ctrl = dvr.Cells[1].Controls[0];

                    if (ctrl is TextBox)
                    {
                        TextBox txt = ctrl as TextBox;

                        txt.Width = 400;
                     
                    }
                }
            }
        }
    }
}

Here is the aspx page:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="update_page.aspx.cs" Inherits="view_page" Title="ESignoff - Update Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <form runat="server">
      <asp:LoginView ID="LoginView1" runat="server">
            <LoggedInTemplate>
                <span style="color: #000099"><strong>Welcome</strong>,</span>
                <asp:LoginName ID="LoginName1" runat="server" Font-Bold="True" ForeColor="Navy" />
                . <span style="color: #000099"><strong>Click here to</strong></span>
                <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutPageUrl="~/login.aspx" />
                <br /><br />
                        <asp:Label ID="ownerLabel" runat="server" Text="Select the Tower:" Width="124px" Height="27px" Font-Bold="True" ForeColor="Navy"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3"
                    DataTextField="CascadeID" DataValueField="CascadeID" Width="124px" OnSelectedIndexChanged="DetailsView1_DataBound">
                </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:towerConnectionString %>"
                    SelectCommand="SELECT [CascadeID] FROM [TowerInfo]"></asp:SqlDataSource>
                &nbsp;&nbsp;<br />
                &nbsp;<asp:TextBox ID="person" runat="server"></asp:TextBox>
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
                    CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
                    Height="50px" Width="438px" DataKeyNames="CascadeID" OnDataBound="DetailsView1_DataBound" >
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                    <EditRowStyle BackColor="#999999" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <Fields>
                        <asp:BoundField DataField="CascadeID" HeaderText="CascadeID" ReadOnly="True" SortExpression="CascadeID" />
                        <asp:BoundField DataField="Owner" HeaderText="Owner" SortExpression="Owner" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Street_Address" HeaderText="Street_Address" SortExpression="Street_Address" />
                        <asp:BoundField DataField="Lit_Towers" HeaderText="Lit_Towers" SortExpression="Lit_Towers" />
                        <asp:BoundField DataField="FCC_ASR" HeaderText="FCC_ASR" SortExpression="FCC_ASR" />
                        <asp:BoundField DataField="Zip_Code" HeaderText="Zip_Code" SortExpression="Zip_Code" />
                        <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
                        <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                        <asp:BoundField DataField="Licensee_ID" HeaderText="Licensee_ID" SortExpression="Licensee_ID" />
                        <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" />
                        <asp:BoundField DataField="Date_Signed_Off" HeaderText="Date_Signed_Off" SortExpression="Date_Signed_Off" />
                        <asp:BoundField DataField="Person_Signing_Off" HeaderText="Person_Signing_Off" SortExpression="Person_Signing_Off" />
                        <asp:BoundField DataField="FRN" HeaderText="FRN" SortExpression="FRN" />
                        <asp:BoundField DataField="FAA_ASN" HeaderText="FAA_ASN" SortExpression="FAA_ASN" />
                        <asp:BoundField DataField="FCC_Link" HeaderText="FCC_Link" SortExpression="FCC_Link" />
                        <asp:BoundField DataField="FAA_Link" HeaderText="FAA_Link" SortExpression="FAA_Link" />
                        <asp:CommandField ButtonType="Button" ShowEditButton="True" />
                        <asp:TemplateField>
                            <EditItemTemplate>

                            </EditItemTemplate>
                        </asp:TemplateField>
                    </Fields>
                </asp:DetailsView>
               
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:towerConnectionString %>"
                    SelectCommand="SELECT [CascadeID], [Owner], [Name], [Street Address] AS Street_Address, [City], [State], [Zip Code] AS Zip_Code, [FCC ASR] AS FCC_ASR, [Lit Towers] AS Lit_Towers, [Licensee ID] AS Licensee_ID, [FRN], [FAA ASN] AS FAA_ASN, [FCC Link] AS FCC_Link, [FAA Link] AS FAA_Link, [Notes], [Person Signing Off] AS Person_Signing_Off, [Date Signed Off] AS Date_Signed_Off FROM [TowerInfo] WHERE ([CascadeID] = @CascadeID)" DeleteCommand="DELETE FROM [TowerInfo] WHERE [CascadeID] = @original_CascadeID" InsertCommand="INSERT INTO [TowerInfo] ([CascadeID], [Owner], [Name], [Street Address], [City], [State], [Zip Code], [FCC ASR], [Lit Towers], [Licensee ID], [FRN], [FAA ASN], [FCC Link], [FAA Link], [Notes], [Person Signing Off], [Date Signed Off]) VALUES (@CascadeID, @Owner, @Name, @Street_Address, @City, @State, @Zip_Code, @FCC_ASR, @Lit_Towers, @Licensee_ID, @FRN, @FAA_ASN, @FCC_Link, @FAA_Link, @Notes, @Person_Signing_Off, @Date_Signed_Off)" UpdateCommand="UPDATE [TowerInfo] SET [Owner] = @Owner, [Name] = @Name, [Street Address] = @Street_Address, [City] = @City, [State] = @State, [Zip Code] = @Zip_Code, [FCC ASR] = @FCC_ASR, [Lit Towers] = @Lit_Towers, [Licensee ID] = @Licensee_ID, [FRN] = @FRN, [FAA ASN] = @FAA_ASN, [FCC Link] = @FCC_Link, [FAA Link] = @FAA_Link, [Notes] = @Notes, [Person Signing Off] = @Person_Signing_Off, [Date Signed Off] = @Date_Signed_Off WHERE [CascadeID] = @original_CascadeID" OldValuesParameterFormatString="original_{0}">
                <DeleteParameters>
                    <asp:Parameter Name="original_CascadeID" Type="String" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="Owner" Type="String" />
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="Street_Address" Type="String" />
                    <asp:Parameter Name="City" Type="String" />
                    <asp:Parameter Name="State" Type="String" />
                    <asp:Parameter Name="Zip_Code" Type="String" />
                    <asp:Parameter Name="FCC_ASR" Type="String" />
                    <asp:Parameter Name="Lit_Towers" Type="String" />
                    <asp:Parameter Name="Licensee_ID" Type="String" />
                    <asp:Parameter Name="FRN" Type="String" />
                    <asp:Parameter Name="FAA_ASN" Type="String" />
                    <asp:Parameter Name="FCC_Link" Type="String" />
                    <asp:Parameter Name="FAA_Link" Type="String" />
                    <asp:Parameter Name="Notes" Type="String" />
                    <asp:Parameter Name="Person_Signing_Off" Type="String" />
                    <asp:Parameter Name="Date_Signed_Off" Type="String" />
                    <asp:Parameter Name="original_CascadeID" Type="String" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="CascadeID" Type="String" />
                    <asp:Parameter Name="Owner" Type="String" />
                    <asp:Parameter Name="Name" Type="String" />
                    <asp:Parameter Name="Street_Address" Type="String" />
                    <asp:Parameter Name="City" Type="String" />
                    <asp:Parameter Name="State" Type="String" />
                    <asp:Parameter Name="Zip_Code" Type="String" />
                    <asp:Parameter Name="FCC_ASR" Type="String" />
                    <asp:Parameter Name="Lit_Towers" Type="String" />
                    <asp:Parameter Name="Licensee_ID" Type="String" />
                    <asp:Parameter Name="FRN" Type="String" />
                    <asp:Parameter Name="FAA_ASN" Type="String" />
                    <asp:Parameter Name="FCC_Link" Type="String" />
                    <asp:Parameter Name="FAA_Link" Type="String" />
                    <asp:Parameter Name="Notes" Type="String" />
                    <asp:Parameter Name="Person_Signing_Off" Type="String" />
                    <asp:Parameter Name="Date_Signed_Off" Type="String" />
                </InsertParameters>
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="CascadeID" PropertyName="SelectedValue"
                        Type="String" />
                </SelectParameters>
                </asp:SqlDataSource>
               
            <br />
                &nbsp; &nbsp;&nbsp;&nbsp;
                <br />
               
            </LoggedInTemplate>
            <AnonymousTemplate>
                <strong><span style="color: #990000">
                You must be logged in to view this page, Click here to</span></strong>
                <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutPageUrl="~/login.aspx" />
            </AnonymousTemplate>
        </asp:LoginView>
    </form>
</asp:Content>

ASKER CERTIFIED SOLUTION
Juan_Barrera

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros