Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted
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"
Posted

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?

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...