woodje
asked on
Making buttons Visible on panal load with FormView
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
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
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.
ASKER
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.TargetIn vocationEx ception was unhandled by user code
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle ._InvokeMe thodFast(O bject target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle .InvokeMet hodFast(Ob ject target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeM ethodInfo. Invoke(Obj ect obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeM ethodInfo. Invoke(Obj ect obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Web.UI.WebControls. ObjectData SourceView .InvokeMet hod(Object DataSource Method method, Boolean disposeInstance, Object& instance) at System.Web.UI.WebControls. ObjectData SourceView .ExecuteSe lect(DataS ourceSelec tArguments arguments) at System.Web.UI.DataSourceVi ew.Select( DataSource SelectArgu ments arguments, DataSourceViewSelectCallba ck callback) at System.Web.UI.WebControls. DataBoundC ontrol.Per formSelect () at System.Web.UI.WebControls. BaseDataBo undControl .DataBind( ) at System.Web.UI.WebControls. FormView.D ataBind() at System.Web.UI.WebControls. BaseDataBo undControl .EnsureDat aBound() at System.Web.UI.WebControls. FormView.E nsureDataB ound() at System.Web.UI.WebControls. CompositeD ataBoundCo ntrol.Crea teChildCon trols() at System.Web.UI.Control.Ensu reChildCon trols() at System.Web.UI.Control.Find Control(St ring id, Int32 pathOffset) at System.Web.UI.Control.Find Control(St ring id) at secure_asc_Default.FormVie w1_Load(Ob ject sender, EventArgs e) in C:\Inetpub\wwwroot\pfo_gat eway\secur e\asc\Defa ult.aspx.v b:line 19 at System.Web.UI.Control.OnLo ad(EventAr gs e) at System.Web.UI.WebControls. DataBoundC ontrol.OnL oad(EventA rgs e) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt)
InnerException: System.ArgumentNullExcepti on
Message="Value cannot be null. Parameter name: sid"
ParamName="sid"
Source="App_Code.bgm9gtol"
StackTrace:
at DataSet1TableAdapters.tbla scTableAda pter.GetDa ta_asc_By_ sid(String sid) in c:\WINDOWS\Microsoft.NET\F ramework\v 2.0.50727\ Temporary ASP.NET Files\pfo_gateway\dcfc321d \d051b320\ App_Code.b gm9gtol.0. cs:line 4196
InnerException:
TargetInvocationException was unhandled by user code
System.Reflection.TargetIn
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle
InnerException: System.ArgumentNullExcepti
Message="Value cannot be null. Parameter name: sid"
ParamName="sid"
Source="App_Code.bgm9gtol"
StackTrace:
at DataSet1TableAdapters.tbla
InnerException:
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.tbla scTableAda pter.GetDa ta_asc_By_ sid(String sid)
Line: 4196
Were you working on other things while waiting for an answer on the buttons?
Looks like you've got a parameter.. "sid" that is pulling a null value....
DataSet1TableAdapters.tbla
Line: 4196
Were you working on other things while waiting for an answer on the buttons?
ASKER
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.
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.
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.
ASKER
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.
Okay, give me a moment to re-look at your original post, my post and see if I can find anything I'm missing.
ASKER
ok please let me know if you need any other information. I can provide you with the aspx page code if you need it.
Actually if you could post your aspx page that would help.
ASKER
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
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.
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.
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.
NEVERMIND, lol. One more minute.
ASKER
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.
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.
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>
ASKER
I know very confusing.
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).
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).
ASKER
Very Strange when I did that it worked.
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?
ASKER
When I change it back. I never even see the seach textbox the error is thrown when the form is being rendered.
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>
<SelectParameters>
<asp:ControlParameter ControlID="asc_sid_search_
PropertyName="Text" Type="String" DefaultValue="-9999" />
</SelectParameters>
ASKER
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.
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.
ASKER
Still getting the error. I have pasted the full stack.
System.NullReferenceExcept ion 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.FormVie w1_Load(Ob ject sender, EventArgs e) in C:\Inetpub\wwwroot\pfo_gat eway\secur e\asc\Defa ult.aspx.v b:line 20 at System.Web.UI.Control.OnLo ad(EventAr gs e) at System.Web.UI.WebControls. DataBoundC ontrol.OnL oad(EventA rgs e) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt)
InnerException:
System.NullReferenceExcept
Message="Object reference not set to an instance of an object."
Source="App_Web_neyv8ceo"
StackTrace:
at secure_asc_Default.FormVie
InnerException:
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.
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.
ASKER
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.
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?
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?
ASKER
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.
ASKER
no the page will load but the button states are not effected.
Please post all your code again with what you currently have.
ASKER
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
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.
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.
ASKER
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.
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.
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.
ASKER
Yes it is a valid value in my database. It is the value I am using in the label.
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.
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.
ASKER
And the full code for the role varification works when using the label as well.
ASKER
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.
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.
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.
ASKER
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.
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.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
ASKER
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
Protected Sub asc_results_pnl_Load(ByVal
Dim btn1 As Button = DirectCast(Formview1.FindC
Dim btn2 AS Button = DirectCast(Formview1.FindC
If User.IsInRole("asc_update"
btn1.visible = true
btn2.visible = true
Else
btn1.visible = false
btn2.visible = false
End If
End Sub