andycharger Posted December 4, 2003 Posted December 4, 2003 Thanks to someone else on the forum, I am now successfully using a function that returns a word to my screen, depending on my userid matching an id that comes from a database. However, I want a button on my screen to only be visible if the condition is True. My Button is called "Button2" and the code on my web page looks like this at the moment: <asp:Button id="Button2" runat="server" text="Edit"></asp:Button> I thought I could use the .visible property of the button in my function but when I open the page the button shows whatever!!! it looks like the .visible property is not being adhered to as the Return value is being written to the screen ok. my code looks like this Public Function myServerFunction(ByVal xID As Integer) As String Dim strName = Session("userid") If (strName) = xID Then Return "Yes" Button2.Visible = True Else Return "No" Button2.Visible = False End If End Function Anyone got any ideas? Quote
fadi Posted December 4, 2003 Posted December 4, 2003 when u put return the function exists directly after the return and it was not process the button2.visible property setting. u should set the visibility then return "yes" or "No" Quote
andycharger Posted December 4, 2003 Author Posted December 4, 2003 I have tried this but now I get the following error: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 66: Line 67: If (strName) = xID Then Line 68: Button2.Visible = True Line 69: Return "Yes" Line 70: Any Ideas to this error? I looks to me like it cannot see the page from the code behind? Quote
fadi Posted December 4, 2003 Posted December 4, 2003 is button2 a web control, if not u should set it to run as server control Quote
Administrators PlausiblyDamp Posted December 4, 2003 Administrators Posted December 4, 2003 Where are you calling this function from? Also why are you returning a string to indicate a True / False condition? Wouldn't a boolean make more sense? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
andycharger Posted December 4, 2003 Author Posted December 4, 2003 Im not declaring my Button2.Visible as a string. Im using that as a boolean! The string "yes" and "No" is just because I am writing that word to the screen. The function sits in the aspx.vb code page behind the aspx page with the button in. Quote
Administrators PlausiblyDamp Posted December 4, 2003 Administrators Posted December 4, 2003 Are you calling the code from the page_load or from a some other event? Also I never suggested you were declaring my Button2.Visible as a string. merely querying why you were returning yes and no as strings. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.