When pressed Once,i want to make the Grid view Button(Time In) invisible until the User press Time Out Button.
Once the user press the Time Out Button,Time in Button must be shown
Have you looked at NServiceBus? Here's an introduction to it. http://www.udidahan.com/2009/02/07/nservicebus-19/
Just use the .Visible property on the buttons. For example:
btnTimeOut.Visible = False 'This will hide it
btnTimeOut.Visible = True ' ... and this will show it
To implement your solution, I'm assuming you've got two separate event handlers for each of your buttons. What you'd want to do is something like this:
Sub btnTimeIn_Click(o as Object, e as EventArgs)
'Hide the button now it has been clicked
Me.btnTimeIn.Visible = False
'Do some other stuff, such as record the Time In here...
End Sub
And then:
Sub btnTimeOut_Click(o as Object, e as EventArgs)
'Show the TimeIn button again
Me.btnTimeIn.Visible = True
'Record the time out etc...
End Sub
You can use the Load or Init events of the form to initialise the state of the buttons, i.e:
If Not Page.IsPostBack
InitialiseButtons()
End If
Private Sub InitialiseButtons()
Me.btnTimeIn.Visible = True
Me.btnTimeOut.Visible = False
End Sub
The "If Not Page.IsPostBack" property will stop your form being accidentally reset when the user clicks on one of your buttons after the initial load.
Hope this helps, feel free to pop any questions back up here.
Cheers
Related
I have a code that when excel opens a userform automatically shows and then allows me to click a button. When I click the button it calls a Main sub to run that code.
In the Main sub I also want another userforms (with a frame, label and button) to popup/show and have the Main Sub code pause until a button is clicked on the new userform.
However the code seems to skip the 2nd userform, it briefly appears as blank, but disappears as the Main sub continues to run to the end.
The code association with the userform (named Notification1) is:
Dim ContDataConvButton As Boolean
Private Sub Notification1_Initialize()
Me.ContDataConvButton = False
Do While Me.ContDataConvButton = False
'do nothing
Loop
End Sub
Private Sub Notification1_Activate()
End Sub
Private Sub Cont_data_conv_button_Click()
Me.ContDataConvButton = True
Unload Me
End Sub
The code in the Main Sub is:
Sub Main()
'code ....
Notification1.show(false) 'I have set it to vbmodeless so that the user can make any changes to the
sheet before clicking the button to continue. Once the button is clicked I would like to return to this
point back in the Main Sub.
Appreciate any advice you can provide to solve this issue.
Regards,
Glenn
I was able to figure it out. I just needed to place a DoEvents statement in the Do While Loop
I just want to control which button user clicked, so I use Session Variable to store that data because I have to create all dynamic control in the Page_Load (to allow event handler work properly). The problem is this Session Variable is not work at the first time I clicked but only the second time.
Here is my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
'For the first time I want this session variable to be false because Image Button is not yet click
Me.Session("ImageClick") = False
End If
If Me.Session("ImageClick") Then
'Then after Button Image is clicked I try to add Dynamic control to a div
AddPreviewTable(0)
CreateButtomButton(Me.Session("totalPage"))
Debug.WriteLine(Me.Session("totalPage"))
Me.Session("ImageClick") = False
End If
End sub
The problem is I have to click on ButtonImage two times to turn Me.Session("ImageClick") to True.
Your if block is incorrect. You need to cast your session object into a bool:
If (Session("ImageClick") Is Not Nothing And CBool(Me.Session("ImageClick"))) Then
'Do your stuff.
End If
I am new to aspx so can someone help me with the following small bit of code. I am trying to create an If statment in aspx.net using Vb, but I can't get it to work correctly.
I am trying to ask a questions and the user has to select a yes checkbox or no checkbox and depending on the answer either a label will appear saying "Not permitted" or a button will appear to link to main form.
I am having problems making either the button or label appear when the user selects choice.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Main_FormBtn.Visible = False
Refer_Label.Visible = False
If CheckBoxNo.Checked = True Then
Refer_Label.Visible = True
ElseIf CheckBoxYes.Checked = True Then
Main_FormBtn.Visible = True
End If
End Sub
Any help would be greatly appricated
thanks
If it is YES OR NO Category Better you use RadioButton Not Checkbox..
Try like below it will help you...
YESRadio_CheckedChanged EVENT
Main_FormBtn.Visible = True
Refer_Label.Visible = False
NORadio_CheckedChanged EVENT
Refer_Label.Visible = True
Main_FormBtn.Visible = False
PAGE_LOAD EVENT
Main_FormBtn.Visible = False
Refer_Label.Visible = False
Before that Set AutoPostBack="true" for RadioButtons
If this is meant to be a form where users go through and answer a number of questions and sub-options appear accordingly there's a number of issues you need to consider. If you want the boxes/labels to show hide when a user clicks something you might need to use javascript/jquery unless you do a postback, in which case you might need to consider that a user might already have selected a number of options/filled out some part of the form.
If you want to share the overall structure of the page it will be easier to give proper advice.
Well as this is on page load, why would you even need this IF statement here? I'm thinking that you actually want this statement within the Click event of the checkbox, not on the page load. This code will only run on the load, not the click.
Double click your ASP button and put this code within the event handler there. Point both of the two checkbox click events to the same method like so;
Page load - You only want to set these to false on the first load.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Main_FormBtn.Visible = False
Refer_Label.Visible = False
End If
End Sub
Click event
Private Sub Checkbox_Click(sender As System.Object, e As System.EventArgs) Handles CheckBoxNo.Click, CheckBoxYes.Click
Main_FormBtn.Visible = False
Refer_Label.Visible = False
If CheckBoxNo.Checked = True Then
Refer_Label.Visible = True
ElseIf CheckBoxYes.Checked = True Then
Main_FormBtn.Visible = True
End If
End Sub
For this to work, it will require a postback. Unless you fancy going into Javascript land.
I have a listview that's showing a long list. Each item has the ability to be 'hidden' or not. I want a checkbox to either show all the list, or not to show the hidden ones. The idea is that users will hide the older items they don't want to see any more, but may want to see at some point. I want to store the value of this decision in a session variable so if the user navigates to another page, then comes back, the ShowAllCheckbox will pre-populate to what the user has previously decided. Everything is working good, except i can't get the session variable to keep. It keeps going back to False. This is what I have:
aspx page:
Show Hidden: <asp:Checkbox ID="ShowHiddenCheckbox" runat="server" AutoPostBack="True" OnCheckedChanged="ShowHiddenCheckboxChange" />
...
<asp:ListView ...>
<!-- this list works fine, and pulls the correct records -->
aspx.vb page:
Protected Sub ShowHiddenCheckBoxChange(ByVal sender As Object, ByVal e As EventArgs)
' toggle the values
Dim CheckBoxField As CheckBox = TryCast(sender, CheckBox)
If CheckBoxField.Checked Then
Session("ShowHiddenRotations") = False
Else
Session("ShowHiddenRotations") = True
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'if i navigate to another page, and come back to this one, this comes back as "False". I don't understand how it could be reset to False.
Response.Write( "Session: " & Session("ShowHiddenRotations") )
'when page loads check if session variable has been set to show/hide the hidden rotations
If Session("ShowHiddenRotations") Then
If Session("ShowHiddenRotations") = True Then
'update sql query on select statement to show the hidden rotations
'update checkbox to show it as checked
ShowHiddenCheckBox.Checked = True
Else
ShowHiddenCheckBox.Checked = False
End If
Else
'not checked by default (ie don't show hidden)
ShowHiddenCheckBox.Checked = False
End If
End Sub
The Session variable always reverts back to False when i navigate to another page and come back to this one. My understanding of session variables was that they would pass their values from one page to another until the user closes the browser. Maybe there's another way of doing this, or something simple I'm missing. Any help is much appreciated! Thanks!
Is session-state enabled on your site? It can be disabled in a couple of different way, on a page level or even in web.config.
You should also be aware the Page_Load event fires for every request, before the check-box auto-postback happens.
I'm also a little confused as to what you're trying to store: I assume every row has a check-box, but it seems you're trying to store the set/not-set value in a single session variable. How do you differentiate which have been selected, and which ones hasn't? :)
Update:
Okay, let's try a clean the code up a little bit. First create a property to access the session value:
Private Property ShowHiddenRotations As Boolean
Get
If Not Session("ShowHiddenRotations") Is Nothing Then
Return CType(Session("ShowHiddenRotations"), Boolean)
Else
Return False
End If
End Get
Set(value As Boolean)
Session("ShowHiddenRotations") = value
End Set
End Property
If you're using that value on other pages, I would recommend moving it to a seperate class.
Then we can reduce your other code to something closer to this:
Protected Sub ShowHiddenCheckBoxChange(ByVal sender As Object, ByVal e As EventArgs)
ShowHiddenRotations = ShowHiddenCheckbox.Checked
End Sub
And ...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If not Page.IsPostBack
' Load your data, better stick it in a seperate sub...
ShowHiddenCheckBox.Checked = ShowHiddenRotations
else
' This section is executed BEFORE any control methods are run, i.e. ShowHiddenCheckBoxChange
end if
End Sub
I'm guessing your problem is really just the order of how things are called in your page. What happens when you debug through it?
I have a wizard control in my asp.net 2.0 project, and it contains a few steps. The second step has a textbox with a standard requiredfieldvalidator control attached to it. When the user clicks Next and the box is empty, the validator complains, all is normal.
However, when the user uses the sidebar steps to skip to the next-to-last step, and clicks Finish, the validator is not fired, and the textbox is empty. In my backend, I have this:
Protected Sub wizard_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizard.FinishButtonClick
If Page.IsValid Then
...
Else
lblError.Text = "You missed some fields, please return and enter them"
e.Cancel = True
End If
End Sub
(lblError is a label on the complete page, but that's not really the issue)
This code does not work...
What is a good solution to this problem? Remove the sidebar and just not use it? Hardly the nicest solution...
It's far from perfect, but I'm now using this as an answer:
Protected Sub wzrdAddEvent_SideBarButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wzrdAddEvent.SideBarButtonClick
If e.NextStepIndex > (e.CurrentStepIndex + 1) Then
e.Cancel = True
End If
End Sub
"if using the sidebar steps, only allow one step forward at the most"