0

Hi, I had some problems on setting the value for a variable when user clicks on the image button.

This is wat I have in the aspx file

<asp:ImageButton ID="NewBtn" runat="server" ImageUrl="image/plus.png" Width="24px" onclick = "newUser = 'True'"/>

At first i tried to declare the variable in code behind as follow

Dim newUser As Boolean

but it gave me an error : is not accessible in this context because it is 'Private'.

Then i change to

Protected newUser As Boolean

Another error shown: 'AddressOf' operand must be the name of a method (without parentheses).


S.O.S!~ I have no idea how to solve this..

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by BlurrieBlue
0

you can't directly set properties from control event handlers. They have to point to methods.

0

you can't directly set properties from control event handlers. They have to point to methods.

Thanks for the reply. I had tried to change the onClientClick to 'NewBtn_Click' event. It can work but after the click and some coding execution, the value can't be change. As example, i use the image button to indicate that user want to add in new user id. The value for newUser will be true as i declare it as Boolean. after the insert query, i assign false to the newUser and get to mofidy the existing record which should perform update query. But it performs insert query instead as the newUser value did not change from true to false as assigned.

0

If NewUser is just a property of the page then it will always be reset each time the page is called because the page is recreated each time. You should probably look into asp.net Sessions to store the value of NewUser, that way the updated value will persist across postbacks.

0

Thanks for the suggestion. How should i pass the variable using Session?.. Any references?

0

You could create a page property using Session to maintain its value

public bool NewUser
{
  get
  {
    return Session["NewUser"] == null ? true : (bool)Session["NewUser"];
  }
  set
  {
    Session["NewUser"] = value;
  }
}

This is C# though, not real sure of the syntax in VB. In this instance if the Session is null then it will return true if the Session variable is not null then it casts it as bool and returns the value.

This page contains some information about using Session

Edited by nakor77: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.