Solved

Making buttons Visible on panal load with FormView

Posted on 2009-07-08
45
682 Views
Last Modified: 2012-05-07
I have an aspx page develeoped with two panals. The first acts as a input paramater's screen when the user presses a button a query is run and the data is returned to a second panal. On this second panal I have a FormView id = FormView1 in the form view in the item template I have three buttons. What I want to do is when the panal loads check and see if the user is in a specific role if they are then make the two hidden buttons visible if not then don't. The two buttons names are:

asc_results_edit_btn
asc_results_insert_btn

The default mode for these buttons is visible = false. I want to change them to true.  In my code behind I have setup the load event but when I enter the button id's here it can't resolve them if I add a dim statement to tell them it is a button then I get a null reference error. I know it has to be something in calling of the buttons but for the life of me I am missing it. Please help.

Jeff


Protected Sub asc_results_pnl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles asc_results_pnl.Load

        If User.IsInRole("asc_update") Then

                

        End If

    End Sub

Open in new window

0
Comment
Question by:woodje
  • 23
  • 22
45 Comments
 
LVL 8

Expert Comment

by:arhame
ID: 24807096
When a button is nested into a formview, you need to cast and findcontrol the button first before making it visible/unvisible.

Protected Sub asc_results_pnl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles asc_results_pnl.Load
        Dim btn1 As Button = DirectCast(Formview1.FindControl("asc_results_edit_btn"), Button)
        Dim btn2 AS Button = DirectCast(Formview1.FindControl("asc_results_insert_btn"), Button)
        If User.IsInRole("asc_update") Then
                btn1.visible = true
                btn2.visible = true
       Else
                btn1.visible = false
                btn2.visible = false
        End If
    End Sub


0
 
LVL 8

Expert Comment

by:arhame
ID: 24807136
Just a random thought, but if you're still getting a null exception error - it might be because the code is in the Panel load event.... try moving it to the Formview.Load event.
0
 

Author Comment

by:woodje
ID: 24807267
Thanks for the response. I have tried the above code on both the panal load and formview load. And I am getting the following error:

TargetInvocationException was unhandled by user code

System.Reflection.TargetInvocationException was unhandled by user code
  Message="Exception has been thrown by the target of an invocation."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)    at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)    at System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance)    at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)    at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)    at System.Web.UI.WebControls.DataBoundControl.PerformSelect()    at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()    at System.Web.UI.WebControls.FormView.DataBind()    at System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()    at System.Web.UI.WebControls.FormView.EnsureDataBound()    at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()    at System.Web.UI.Control.EnsureChildControls()    at System.Web.UI.Control.FindControl(String id, Int32 pathOffset)    at System.Web.UI.Control.FindControl(String id)    at secure_asc_Default.FormView1_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\pfo_gateway\secure\asc\Default.aspx.vb:line 19    at System.Web.UI.Control.OnLoad(EventArgs e)    at System.Web.UI.WebControls.DataBoundControl.OnLoad(EventArgs e)    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.ArgumentNullException
       Message="Value cannot be null. Parameter name: sid"
       ParamName="sid"
       Source="App_Code.bgm9gtol"
       StackTrace:
            at DataSet1TableAdapters.tblascTableAdapter.GetData_asc_By_sid(String sid) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\pfo_gateway\dcfc321d\d051b320\App_Code.bgm9gtol.0.cs:line 4196
       InnerException:
0
 
LVL 8

Expert Comment

by:arhame
ID: 24807297
Looks like that has nothing to do with the buttons...

Looks like you've got a parameter.. "sid" that is pulling a null value....
DataSet1TableAdapters.tblascTableAdapter.GetData_asc_By_sid(String sid)
Line: 4196

Were you working on other things while waiting for an answer on the buttons?
0
 

Author Comment

by:woodje
ID: 24807356
No, what this page has is two panal's the first has a textbox that a user enters a five digit number in the presses search this makes the first panel not visible and makes the second panal visible. In the second panal when it becomes visible the form fills in based on the data entered in the first panal. If I comment out the user role check this works fine. It just will not make the buttons visible that I want.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24807400
Okay, very weird for sure - this is fairly basic.

Curious - if you take out the If statement checking the users role, and just leave the code to dim/cast the buttons and make them not visible... does it work then?

What I'm thinking is maybe you don't have users/roles setup on the application yet, and when it's looking for the role you're in... it's finding nothing and throwing that null exception on the fact it can't find.  Has to be something oddball like that, I've done stuff similiar to what you're doing a million times.  It's as straight forward as can be.
0
 

Author Comment

by:woodje
ID: 24807505
No when comment out the if, else, and endif and the visible = false lines. I get the same errror. I have the two button default setting of visible set to false. So I used the btn1 and btn2 .visible= true. The users.roles is setup I am using this to determine which menu items to make available to a user with the menu control and sitemap control.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24807519
Okay, give me a moment to re-look at your original post, my post and see if I can find anything I'm missing.
0
 

Author Comment

by:woodje
ID: 24807537
ok please let me know if you need any other information. I can provide you with the aspx page code if you need it.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24807550
Actually if you could post your aspx page that would help.
0
 

Author Comment

by:woodje
ID: 24807602
Here is the code I broke it out into the page and code behind.
***aspx page ***

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="secure_asc_Default" title="Untitled Page" %>
 

<asp:Content ID="Content2" ContentPlaceHolderID="cp_content" Runat="Server">
 

<div>

    <asp:Panel ID="asc_master_pnl" runat="server">

        <asp:Panel ID="asc_search_pnl" runat="server">

            <center>

            <asp:Label ID="asc_sid_search_lbl" runat="server" Text="Please enter the SID you wish to check the Authentication Status on."></asp:Label><br />

            <asp:TextBox ID="asc_sid_search_txt" runat="server" MaxLength="5" />

            <br /><br />

            <asp:Button ID="asc_search_btn" runat="server" Text="Search" />

            <asp:Button ID="asc_reset_btn" runat="server" Text="Reset" /><br /><br />

            <asp:Literal ID="asc_error_lit" runat="server"></asp:Literal>

            </center>

        </asp:Panel>

        <asp:Panel ID="asc_results_pnl" runat="server" Visible="false">

            <center>

                <asp:FormView ID="FormView1" runat="server" DataKeyNames="recid" 

                    DataSourceID="asc_ods">

                    <EditItemTemplate>

                        <table width="100%">

                            <tr>

                                <td colspan="2">Authentication Result Form</td>

                            </tr>

                            <tr>

                                <td>SID:</td>

                                <td>Authentication Enabled:</td>

                            </tr>

                            <tr>

                                <td align="left" width="400px"><asp:TextBox ID="sidTextBox" runat="server" ReadOnly="true" Text='<%# Bind("sid") %>' /></td>

                                <td><asp:CheckBox ID="auth_enabledCheckBox" runat="server" Checked='<%# Bind("auth_enabled") %>' /></td>

                            </tr>

                            <tr>

                                <td>SID Description:</td>

                                <td>Brownout:</td>

                            </tr>

                            <tr>

                                <td align="left"><asp:TextBox ID="sid_descriptionTextBox" runat="server" ReadOnly="true" Text='<%# Bind("sid_description") %>' /></td>

                                <td><asp:CheckBox ID="brownoutCheckBox" runat="server" Checked='<%# Bind("brownout") %>' /></td>

                            </tr>

                            <tr>

                                <td colspan="2">Notes:</td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="left"><asp:TextBox ID="notesTextBox" runat="server" Text='<%# Bind("notes") %>' TextMode="MultiLine" /></td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="center">                                    

                                    <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />

                                    <asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />                        

                                </td>

                            </tr>

                        </table>                        

                    </EditItemTemplate>

                    <InsertItemTemplate>

                        <table width="100%">

                            <tr>

                                <td colspan="2">Authentication Result Form</td>

                            </tr>

                            <tr>

                                <td>SID:</td>

                                <td>Authentication Enabled:</td>

                            </tr>

                            <tr>

                                <td align="left" width="400px"><asp:TextBox ID="sidTextBox" runat="server" Text='<%# Bind("sid") %>' /></td>

                                <td><asp:CheckBox ID="auth_enabledCheckBox" runat="server" Checked='<%# Bind("auth_enabled") %>' /></td>

                            </tr>

                            <tr>

                                <td>SID Description:</td>

                                <td>Brownout:</td>

                            </tr>

                            <tr>

                                <td align="left"><asp:TextBox ID="sid_descriptionTextBox" runat="server" Text='<%# Bind("sid_description") %>' /></td>

                                <td><asp:CheckBox ID="brownoutCheckBox" runat="server" Checked='<%# Bind("brownout") %>' /></td>

                            </tr>

                            <tr>

                                <td colspan="2">Notes:</td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="left"><asp:TextBox ID="notesTextBox" runat="server" TextMode="MultiLine" Text='<%# Bind("notes") %>' /></td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="center">

                                    <asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />

                                    <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />                        

                                </td>

                            </tr>

                        </table>                    

                    </InsertItemTemplate>

                    <ItemTemplate>

                        <table width="100%">

                            <tr>

                                <td colspan="2">Authentication Result Form</td>

                            </tr>

                            <tr>

                                <td>SID:</td>

                                <td>Authentication Enabled:</td>

                            </tr>

                            <tr>

                                <td align="left" width="400px"><asp:TextBox ID="TextBox1" runat="server" Width="400px" ReadOnly="True" Text='<%# Bind("sid") %>'></asp:TextBox></td>

                                <td><asp:CheckBox ID="CheckBox1" runat="server" Enabled="false" Checked='<%# Bind("auth_enabled") %>' /></td>

                            </tr>

                            <tr>

                                <td>SID Description:</td>

                                <td>Brownout:</td>

                            </tr>

                            <tr>

                                <td align="left"><asp:TextBox ID="TextBox2" runat="server" MaxLength="65" Width="400px" ReadOnly="True" Text='<%# Bind("sid_description") %>'></asp:TextBox></td>

                                <td><asp:CheckBox ID="CheckBox2" runat="server" Enabled="false" Checked='<%# Bind("brownout") %>' /></td>

                            </tr>

                            <tr>

                                <td colspan="2">Notes:</td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="left"><asp:TextBox ID="TextBox3" runat="server" Width="100%" ReadOnly="True" 

                            TextMode="MultiLine" Text='<%# Bind("notes") %>'></asp:TextBox></td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="center">

                                    <asp:Button ID="asc_results_close_btn" runat="server" Text="Cancel" 

                                        onclick="asc_results_close_btn_Click" />

                                    <asp:Button ID="asc_results_edit_btn" runat="server" Text="Edit" Visible="false" CommandName="Edit" CausesValidation="False"/>

                                    <asp:Button ID="asc_results_insert_btn" runat="server" Text="Insert" Visible="false" CommandName="New" CausesValidation="False"/>                        

                                </td>

                            </tr>

                        </table>

                    </ItemTemplate>

                </asp:FormView>

            </center>

            <asp:ObjectDataSource ID="asc_ods" runat="server" DeleteMethod="Delete" 

                InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 

                SelectMethod="GetData_asc_By_sid" 

                TypeName="DataSet1TableAdapters.tblascTableAdapter" UpdateMethod="Update">

                <DeleteParameters>

                    <asp:Parameter Name="Original_recid" Type="Decimal" />

                </DeleteParameters>

                <UpdateParameters>

                    <asp:Parameter Name="sid" Type="String" />

                    <asp:Parameter Name="sid_description" Type="String" />

                    <asp:Parameter Name="auth_enabled" Type="Boolean" />

                    <asp:Parameter Name="brownout" Type="Boolean" />

                    <asp:Parameter Name="notes" Type="String" />

                    <asp:Parameter Name="Original_recid" Type="Decimal" />

                </UpdateParameters>

                <SelectParameters>

                    <asp:ControlParameter ControlID="asc_sid_search_txt" Name="sid" 

                        PropertyName="Text" Type="String" />

                </SelectParameters>

                <InsertParameters>

                    <asp:Parameter Name="sid" Type="String" />

                    <asp:Parameter Name="sid_description" Type="String" />

                    <asp:Parameter Name="auth_enabled" Type="Boolean" />

                    <asp:Parameter Name="brownout" Type="Boolean" />

                    <asp:Parameter Name="notes" Type="String" />

                </InsertParameters>

            </asp:ObjectDataSource>                                    

        </asp:Panel>        

    </asp:Panel>    

</div>

</asp:Content>
 
 

***code behind***
 
 

Partial Class secure_asc_Default

    Inherits System.Web.UI.Page

    Protected Sub asc_search_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles asc_search_btn.Click

        asc_search_pnl.Visible = False

        asc_results_pnl.Visible = True

    End Sub

    Protected Sub asc_results_pnl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles asc_results_pnl.Load

        

    End Sub

    Protected Sub asc_results_close_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        asc_search_pnl.Visible = True

        asc_results_pnl.Visible = False

        asc_sid_search_txt.Text = ""

        asc_sid_search_txt.Focus()

    End Sub
 

    Protected Sub FormView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.Load

        'Dim btn1 As Button = DirectCast(FormView1.FindControl("asc_results_edit_btn"), Button)

        'Dim btn2 As Button = DirectCast(FormView1.FindControl("asc_results_insert_btn"), Button)

        'If User.IsInRole("asc_update") Then

        'btn1.Visible = True

        'btn2.Visible = True

        'Else

        'btn1.Visible = False

        'btn2.Visible = False

        'End If

    End Sub

End Class

Open in new window

0
 
LVL 8

Expert Comment

by:arhame
ID: 24807738
Man, everything looks good as far as finding the buttons and stuff goes - you're in the item template etc.

One thing I did notice though, that kind of relates to the error you were getting - but not to why it'd work with the code commented out.....  you empty out the search parameters text, the one you're passing to your object data source to be used as a select parameter...  Which would give the parameter that you call (and it mentions in the error) sid as nothing.

Try commenting out this line and see what it does for me please:
asc_sid_search_txt.Text = ""

I'm going to keep looking, just something I noticed and figured you could try while I'm still looking.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24807753
Actually I take that back, you only call that when you actually close the panel from the results panel... for some reason I saw it the first time as when you clicked search.

NEVERMIND, lol.  One more minute.
0
 

Author Comment

by:woodje
ID: 24807779
No go on that as well. I commented out line 14 and commented in lines 19,20,22,&23. Same error on the first dim statement.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24807904
Okay, I gutted your formview, and left the buttons but removed everything else (since obviously without your database I can't use your object datasource).  I attached it to a sql datasource of my own that just pulled values (never bind to them, just needed it to load the item template).... used the same dim/cast... and it works fine.... in the same panel setup, using the same search panels and everything.  Only thing changed was the ods.

So now I'm really confused, without the binding/ods you're using - it works fine.  WIthout the dims... the ods you're working is fine.  This makes no sense......

What a mess.  Let me keep trying.
        Dim btn1 As Button = DirectCast(FormView1.FindControl("asc_results_edit_btn"), Button)

        Dim btn2 As Button = DirectCast(FormView1.FindControl("asc_results_insert_btn"), Button)
 

        btn1.Visible = True

        btn2.Visible = True
 
 
 

****** Fomview
 

<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">

                    <ItemTemplate>

                        <asp:Button ID="asc_results_close_btn" runat="server" Text="Cancel" 

                            onclick="asc_results_close_btn_Click" />

                        <asp:Button ID="asc_results_edit_btn" runat="server" Text="Edit" Visible="false" CommandName="Edit" CausesValidation="False"/>

                        <asp:Button ID="asc_results_insert_btn" runat="server" Text="Insert" Visible="false" CommandName="New" CausesValidation="False"/>                        

                        

                    </ItemTemplate>

                </asp:FormView>

Open in new window

0
 

Author Comment

by:woodje
ID: 24807940
I know very confusing.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808005
Everything, even your error keeps pointing back to the time when you have the dims.... the sid being blank, will you try it again and make _double_ sure that you actually entered a number or value into the search box?

If you do... lets try changing where it's getting the value from.... add:

<asp:Label ID="TestLabel" runat="server" Text="123"></asp:Label>

But.... change the Text to a known good SID, so that way we ALWAYS know where it's looking will have a value and it has nothing set to change that.

Then just change the select parameter to:
<SelectParameters>
                    <asp:ControlParameter ControlID="TestLabel" Name="sid"
                        PropertyName="Text" Type="String" />
                </SelectParameters>

I know this seems a little redundent - but there is something weird going on here.... and the error message you get when we actually cast the buttons in a proper way is informing us that the object data source is getting a null value for the 'sid'......... completely unrelated to the buttons (your original post).
0
 

Author Comment

by:woodje
ID: 24808068
Very Strange when I did that it worked.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808082
Okay, but if you leave it as the textbox.... and you type in a known good sid there (change it back)... and are 100% sure you type in a good sid... back to the same error?
0
 

Author Comment

by:woodje
ID: 24808111
When I change it back. I never even see the seach textbox the error is thrown when the form is being rendered.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808137
Try setting a defaultvalue on the selectparameter... something that it would obviously never be... example:

                <SelectParameters>
                    <asp:ControlParameter ControlID="asc_sid_search_txt" Name="sid"
                        PropertyName="Text" Type="String" DefaultValue="-9999" />
                </SelectParameters>
0
 

Author Comment

by:woodje
ID: 24808182
ok the error has changed. I am now getting a null reference error on the btn1.Visible = True. Still have not even seen the seach screen yet.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 8

Expert Comment

by:arhame
ID: 24808198
Ahhh, since it's not pulling back any records... it's not going to create the button....  Change the DefaultValue="  "  to the same value you did for the label.
0
 

Author Comment

by:woodje
ID: 24808237
Still getting the error. I have pasted the full stack.

System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  Source="App_Web_neyv8ceo"
  StackTrace:
       at secure_asc_Default.FormView1_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\pfo_gateway\secure\asc\Default.aspx.vb:line 20    at System.Web.UI.Control.OnLoad(EventArgs e)    at System.Web.UI.WebControls.DataBoundControl.OnLoad(EventArgs e)    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Control.LoadRecursive()    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808262
Man......... 30 posts later, laugh.........

Move the code under the asc_search_btn_Click event... instead of when it loads, so it doesn't cry when the page first loads... the dim button commands.
0
 

Author Comment

by:woodje
ID: 24808343
Maybe this will help. I redid the default value in the select statement and entered a value that does exsist in the database and it will let the panal's render and then when you enter the data you are looking for it will retrieve that data.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808377
Should do the same thing when you set it's default value.  But that works too.

Now, if you leave it like that - and uncomment the dim button code under either the formview1.load event, or the asc_search_btn_Click.... will it allow the page to load?  Or are you back to a null value when you uncomment the first dim. before you even see a search?
0
 

Author Comment

by:woodje
ID: 24808387
I moved the data from FormView1_Load to the onclick and it did not help. The panals are rendering and the data is retrieving but the buttons are not becoming visible.
0
 

Author Comment

by:woodje
ID: 24808395
no the page will load but the button states are not effected.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808409
Please post all your code again with what you currently have.
0
 

Author Comment

by:woodje
ID: 24808422
Here you go.
****aspx page****
 

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="secure_asc_Default" title="Untitled Page" %>
 

<asp:Content ID="Content2" ContentPlaceHolderID="cp_content" Runat="Server">
 

<div>

    <asp:Panel ID="asc_master_pnl" runat="server">

        <asp:Panel ID="asc_search_pnl" runat="server">

            <center>

            <asp:Label ID="asc_sid_search_lbl" runat="server" Text="Please enter the SID you wish to check the Authentication Status on."></asp:Label><br />

            <!--<asp:Label ID="TestLabel" runat="server" Text="00022"></asp:Label>-->

            <asp:TextBox ID="asc_sid_search_txt" runat="server" MaxLength="5" />

            <br /><br />

            <asp:Button ID="asc_search_btn" runat="server" Text="Search" />

            <asp:Button ID="asc_reset_btn" runat="server" Text="Reset" /><br /><br />

            <asp:Literal ID="asc_error_lit" runat="server"></asp:Literal>

            </center>

        </asp:Panel>

        <asp:Panel ID="asc_results_pnl" runat="server" Visible="false">

            <center>

                <asp:FormView ID="FormView1" runat="server" DataKeyNames="recid" 

                    DataSourceID="asc_ods">

                    <EditItemTemplate>

                        <table width="100%">

                            <tr>

                                <td colspan="2">Authentication Result Form</td>

                            </tr>

                            <tr>

                                <td>SID:</td>

                                <td>Authentication Enabled:</td>

                            </tr>

                            <tr>

                                <td align="left" width="400px"><asp:TextBox ID="sidTextBox" runat="server" ReadOnly="true" Text='<%# Bind("sid") %>' /></td>

                                <td><asp:CheckBox ID="auth_enabledCheckBox" runat="server" Checked='<%# Bind("auth_enabled") %>' /></td>

                            </tr>

                            <tr>

                                <td>SID Description:</td>

                                <td>Brownout:</td>

                            </tr>

                            <tr>

                                <td align="left"><asp:TextBox ID="sid_descriptionTextBox" runat="server" ReadOnly="true" Text='<%# Bind("sid_description") %>' /></td>

                                <td><asp:CheckBox ID="brownoutCheckBox" runat="server" Checked='<%# Bind("brownout") %>' /></td>

                            </tr>

                            <tr>

                                <td colspan="2">Notes:</td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="left"><asp:TextBox ID="notesTextBox" runat="server" Text='<%# Bind("notes") %>' TextMode="MultiLine" /></td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="center">                                    

                                    <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />

                                    <asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" onclick="asc_results_close_btn_Click" />                        

                                </td>

                            </tr>

                        </table>                        

                    </EditItemTemplate>

                    <InsertItemTemplate>

                        <table width="100%">

                            <tr>

                                <td colspan="2">Authentication Result Form</td>

                            </tr>

                            <tr>

                                <td>SID:</td>

                                <td>Authentication Enabled:</td>

                            </tr>

                            <tr>

                                <td align="left" width="400px"><asp:TextBox ID="sidTextBox" runat="server" Text='<%# Bind("sid") %>' /></td>

                                <td><asp:CheckBox ID="auth_enabledCheckBox" runat="server" Checked='<%# Bind("auth_enabled") %>' /></td>

                            </tr>

                            <tr>

                                <td>SID Description:</td>

                                <td>Brownout:</td>

                            </tr>

                            <tr>

                                <td align="left"><asp:TextBox ID="sid_descriptionTextBox" runat="server" Text='<%# Bind("sid_description") %>' /></td>

                                <td><asp:CheckBox ID="brownoutCheckBox" runat="server" Checked='<%# Bind("brownout") %>' /></td>

                            </tr>

                            <tr>

                                <td colspan="2">Notes:</td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="left"><asp:TextBox ID="notesTextBox" runat="server" TextMode="MultiLine" Text='<%# Bind("notes") %>' /></td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="center">

                                    <asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" onclick="asc_results_close_btn_Click"/>

                                    <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />                        

                                </td>

                            </tr>

                        </table>                    

                    </InsertItemTemplate>

                    <ItemTemplate>

                        <table width="100%">

                            <tr>

                                <td colspan="2">Authentication Result Form</td>

                            </tr>

                            <tr>

                                <td>SID:</td>

                                <td>Authentication Enabled:</td>

                            </tr>

                            <tr>

                                <td align="left" width="400px"><asp:TextBox ID="TextBox1" runat="server" Width="400px" ReadOnly="True" Text='<%# Bind("sid") %>'></asp:TextBox></td>

                                <td><asp:CheckBox ID="CheckBox1" runat="server" Enabled="false" Checked='<%# Bind("auth_enabled") %>' /></td>

                            </tr>

                            <tr>

                                <td>SID Description:</td>

                                <td>Brownout:</td>

                            </tr>

                            <tr>

                                <td align="left"><asp:TextBox ID="TextBox2" runat="server" MaxLength="65" Width="400px" ReadOnly="True" Text='<%# Bind("sid_description") %>'></asp:TextBox></td>

                                <td><asp:CheckBox ID="CheckBox2" runat="server" Enabled="false" Checked='<%# Bind("brownout") %>' /></td>

                            </tr>

                            <tr>

                                <td colspan="2">Notes:</td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="left"><asp:TextBox ID="TextBox3" runat="server" Width="100%" ReadOnly="True" 

                            TextMode="MultiLine" Text='<%# Bind("notes") %>'></asp:TextBox></td>                    

                            </tr>

                            <tr>

                                <td colspan="2" align="center">

                                    <asp:Button ID="asc_results_close_btn" runat="server" Text="Cancel" 

                                        onclick="asc_results_close_btn_Click" />

                                    <asp:Button ID="asc_results_edit_btn" runat="server" Text="Edit" Visible="false" CommandName="Edit" CausesValidation="False"/>

                                    <asp:Button ID="asc_results_insert_btn" runat="server" Text="Insert" Visible="false" CommandName="New" CausesValidation="False"/>                        

                                </td>

                            </tr>

                        </table>

                    </ItemTemplate>

                </asp:FormView>

            </center>

            <asp:ObjectDataSource ID="asc_ods" runat="server" DeleteMethod="Delete" 

                InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 

                SelectMethod="GetData_asc_By_sid" 

                TypeName="DataSet1TableAdapters.tblascTableAdapter" UpdateMethod="Update">

                <DeleteParameters>

                    <asp:Parameter Name="Original_recid" Type="Decimal" />

                </DeleteParameters>

                <UpdateParameters>

                    <asp:Parameter Name="sid" Type="String" />

                    <asp:Parameter Name="sid_description" Type="String" />

                    <asp:Parameter Name="auth_enabled" Type="Boolean" />

                    <asp:Parameter Name="brownout" Type="Boolean" />

                    <asp:Parameter Name="notes" Type="String" />

                    <asp:Parameter Name="Original_recid" Type="Decimal" />

                </UpdateParameters>

                <SelectParameters>

                    <asp:ControlParameter ControlID="asc_sid_search_txt" Name="sid" 

                        PropertyName="Text" Type="String" DefaultValue="00022" />

                </SelectParameters>

                <InsertParameters>

                    <asp:Parameter Name="sid" Type="String" />

                    <asp:Parameter Name="sid_description" Type="String" />

                    <asp:Parameter Name="auth_enabled" Type="Boolean" />

                    <asp:Parameter Name="brownout" Type="Boolean" />

                    <asp:Parameter Name="notes" Type="String" />

                </InsertParameters>

            </asp:ObjectDataSource>                                    

        </asp:Panel>        

    </asp:Panel>    

</div>

</asp:Content>
 

****code behind****
 
 

Partial Class secure_asc_Default

    Inherits System.Web.UI.Page
 

    Protected Sub asc_search_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles asc_search_btn.Click

        asc_search_pnl.Visible = False

        asc_results_pnl.Visible = True

        Dim btn1 As Button = DirectCast(FormView1.FindControl("asc_results_edit_btn"), Button)

        Dim btn2 As Button = DirectCast(FormView1.FindControl("asc_results_insert_btn"), Button)

        'If User.IsInRole("asc_update") Then

        btn1.Visible = True

        btn2.Visible = True

        'Else

        'btn1.Visible = False

        'btn2.Visible = False

        'End If

    End Sub

    

    Protected Sub asc_results_close_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        asc_search_pnl.Visible = True

        asc_results_pnl.Visible = False

        asc_sid_search_txt.Text = ""

        asc_sid_search_txt.Focus()

    End Sub
 

    Protected Sub FormView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.Load

        

    End Sub

End Class

Open in new window

0
 
LVL 8

Expert Comment

by:arhame
ID: 24808484
Okay, so in the button click event it doesn't error - just doesn't work.
I assume if you put it in the formview1.load event - we go back to the same error.

Try making an event for each button.load - put the dim button event in both buttons events.... we'll know for a fact it's loaded and is there, if it calls the load event.
0
 

Author Comment

by:woodje
ID: 24808564
No it will not error now that I have a valid default value from the data source. And when I created the load events I now have an error that says btn1 and btn2 are not declared. It can't seem to find them.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808651
But it finds them perfectly fine back when we set the selectparameter to a label with text of a valid sid?
Man, I'm really at a loss.  This works fine in my situation using your same panels/formview setup, just a different datasource.  The value you're entering into the textbox is a valid sid still, correct?  It would have to be... or else I imagine it wouldn't even fire the button.load event.

Let me finish up the code I'm working on for this project, and I'll take another detailed look at this.  Maybe I'm missing something obvious, but the fact it works when you use a label to set the sid, but not a textbox is absolutely rediculous... that has no bearing on whether or not it can find the buttons.  But I'll take one more good look and I might have to throw in the towel... I am at a loss at what is going on there.

0
 

Author Comment

by:woodje
ID: 24808668
Yes it is a valid value in my database. It is the value I am using in the label.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808678
Okay.

And just so I understood you, when you said "It worked" when we switched the Select Parameter from the textbox to the label... you meant it all worked right?  Not just that it loaded, but that it could find the buttons and all?  Obviously that's not going to work, you need to have a variable SID... but just so I can chew on it while thinking.
0
 

Author Comment

by:woodje
ID: 24808701
And the full code for the role varification works when using the label as well.
0
 

Author Comment

by:woodje
ID: 24808714
Yes with the label and the full code the screens render and the buttons become visible or not based on the role of the user that is logged in.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24808761
Okay, so it's having problems with grabbing the value from the textbox after the panel the textbox in is hidden maybe? A workaround for this could be like this:

Set the Select Parameter back to the label, set the labels visiblity to false BUT keep the label outside of either of the panels (so it's always present).  Set the text of the label to a valid sid. When you click the search button, set the value of the label, to the text entered into the textbox.  Then formview1.Databind() so it gets the databased on the new text of the label.



0
 

Author Comment

by:woodje
ID: 24824203
Still working on this. I don't understand how with the code that I have I am just asking that when the panal becomes visible that it check to see what role the person is in and to then make the buttons visible or not based on that. What is entered in the txt box should have no bearing on this.
0
 
LVL 8

Expert Comment

by:arhame
ID: 24824271
Oh I agree completely.  That day I even setup my own test similiar to what you have, minus using your object data source I used a sqldatasource that could pull data from my database (since I obviously don't have access to yours) and it worked perfectly fine.  So the only thing I can see different between your setup and the one I had, was the object data source - but unless the datasource isn't pulling back any data (IE it's not loading a template) that should have absolutely no bearing on how or if you can access the buttons.
0
 

Author Comment

by:woodje
ID: 24824305
I agree and if I dont enter any data in the text box and press search because we have the default set. It does bring back that record. So I know it is talking to the database and is retreiving data.
0
 
LVL 8

Accepted Solution

by:
arhame earned 500 total points
ID: 24824323
Can you post just your code behind file one more time as it currently is?
0
 

Author Comment

by:woodje
ID: 24824355
Sure just noticed something. If I leave the text box blank and let the default pass the value the buttons will be visible. However when you enter a value it doesn't make them visible. Is it something in the order of the processing that can be causing the issue?
****code behind****
 
 

Partial Class secure_asc_Default

    Inherits System.Web.UI.Page
 

    Protected Sub asc_search_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles asc_search_btn.Click

        asc_search_pnl.Visible = False

        asc_results_pnl.Visible = True

    End Sub

    

    Protected Sub asc_results_close_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        asc_search_pnl.Visible = True

        asc_results_pnl.Visible = False

        asc_sid_search_txt.Text = ""

        asc_sid_search_txt.Focus()

    End Sub
 

    Protected Sub FormView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.Load

        Dim btn1 As Button = DirectCast(FormView1.FindControl("asc_results_edit_btn"), Button)

        Dim btn2 As Button = DirectCast(FormView1.FindControl("asc_results_insert_btn"), Button)

        If User.IsInRole("asc_update") Then

            btn1.Visible = True

            btn2.Visible = True

        Else

            btn1.Visible = False

            btn2.Visible = False

        End If

    End Sub

End Class

Open in new window

0
 

Author Comment

by:woodje
ID: 24824437
Got it. It was in the order of events. The FormView1 was loaded and the buttons were visible then when I pressed the seach button a new event fired and the panal's changed status. So the buttons went back to their default. I changed the code to put the button transition in the seach on click event and it works fine now. This was a strange one. I will have to remember it for the future. Thanks for all your help. I have included the code behind as it is while working below. Again thanks for all of your work on this.


Partial Class secure_asc_Default

    Inherits System.Web.UI.Page
 

    Protected Sub asc_search_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles asc_search_btn.Click

        asc_search_pnl.Visible = False

        asc_results_pnl.Visible = True
 

        Dim btn1 As Button = DirectCast(FormView1.FindControl("asc_results_edit_btn"), Button)

        Dim btn2 As Button = DirectCast(FormView1.FindControl("asc_results_insert_btn"), Button)

        If User.IsInRole("asc_update") Then

            btn1.Visible = True

            btn2.Visible = True

        Else

            btn1.Visible = False

            btn2.Visible = False

        End If

    End Sub

    

    Protected Sub asc_results_close_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        asc_search_pnl.Visible = True

        asc_results_pnl.Visible = False

        asc_sid_search_txt.Text = ""

        asc_sid_search_txt.Focus()

    End Sub
 

    Protected Sub FormView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.Load

        

    End Sub

End Class

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now