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
Related
I have very strange issues. I have used Update Panels before and never had issues but because I am grouping listviews I get the issues. I have about 4 Update Panels on a page which I call by using the panelname.update() in code behind, and used to all work.
Then because I had to group a bunch of listviews inside each other I had to use a PageLoad to DataBind rather than actually putting the data sources on the asp page. The data all works with Listview when page loads, but now the update panels don't work on async postback at all.
If I take out uppnlSOL.Update() in code behind all the rest start working again. The update panel that causes the issue is the same one that contains the listview with the DataBind.
ASP page has all panels have childrenastriggers="false" UpdateMode="Conditional" hence I call them all from code behind. I also tried removing the uppnlSOL.Update() from code behind and placing a trigger on the uppnlSOL on the asp page. As soon as it launches I get same result. I removed the trigger then the other 3 panels work again. I need all 4 working and
I am confused, its almost like its rendering while its trying to do the update panel or something. I even tried a pause for 3 seconds after DataBind then trying updatepanel.Update() and all 4 still didn't work.
I will try to put some code below of what is sort of going on.
Protected Sub Packing_Load(sender As Object, e As EventArgs) Handles Me.Load
If IsPostBack = False Then
lvSOLGrpDelAdd.DataSource = tblDespatchA.DespatchPackSOLGrpDelAdd_Get(IDSO:=hdnIDSO.Value)
lvSOLGrpDelAdd.DataBind()
End If
End Sub
Protected Sub lvSOLGrpDelAdd_RowDataBound(sender As Object, e As ListViewItemEventArgs) Handles lvSOLGrpDelAdd.ItemDataBound
Dim lvSOLGrpDelMeth As ListView = DirectCast(e.Item.FindControl("lvSOLGrpDelMeth"), ListView)
lvSOLGrpDelMeth.DataSource = tblDespatchA.DespatchPackSOLGrpDelMeth_Get(IDSO:=hdnIDSO.Value, IDGrpDelAdd:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelAdd"))
lvSOLGrpDelMeth.DataBind()
End Sub
Protected Sub lvSOLGrpDelMeth_RowDataBound(sender As Object, e As ListViewItemEventArgs)
Dim lvSOL As ListView = DirectCast(e.Item.FindControl("lvSOL"), ListView)
lvSOL.DataSource = tblDespatchA.DespatchPackSOL_Get(IDSO:=hdnIDSO.Value, IDGrpDelAdd:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelAdd").ToString, IDGrpDelMeth:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelMeth").ToString)
lvSOL.DataBind()
End Sub
Protected Sub btnAllocateLine_Click(sender As Object, e As EventArgs)
Dim lvRow As Object = DirectCast(sender, Object).Parent
Dim hdnIDSOL As HiddenField = DirectCast(lvRow.FindControl("hdnIDSOL"), HiddenField)
Dim lstQtyAvail As DropDownList = DirectCast(lvRow.FindControl("lstQtyAvail"), DropDownList)
tblDespatchA.DespatchPackSOLAllocate_Save(IDSO:=hdnIDSO.Value, IDSOL:=hdnIDSOL.Value, AllocateQty:=lstQtyAvail.SelectedValue)
Bind()
End Sub
Protected Sub Bind()
uppnlDOL.DataBind()
uppnlDOL.Update()
uppnlDBox.DataBind()
uppnlDBox.Update()
uppnlFooter.DataBind()
uppnlFooter.Update()
'I HAVE TO REGET FROM DATABASE CHANGES THAT HAVE HAPPEN AND
'I KNOW THIS BIT WORKS BECAUSE I HAVE TESTED THE DATA.
lvSOLGrpDelAdd.DataSource = tblDespatchA.DespatchPackSOLGrpDelAdd_Get(IDSO:=hdnIDSO.Value)
lvSOLGrpDelAdd.DataBind()
uppnlSOL.Update() ' THIS BIT WHEN I PUT IN THIS MAKES ALL THE OTHER PANELS CRASH
End Sub
Here we go again I answer my own question because nobody would help, but I will help anyone else with similar situation because I'm nice.
The reason it crashed all the other panels is because on my ASP.net page had some generated code in there using <% Response.Write("stuff here") %> and because of using the Response.Write caused it crash.
The Update Panels are doing a async post back and me calling a Response.Write() at the same time as PanelName.Update() caused this issue. I am looking for another method to write to the screen without using response.write and that would solve my 2nd problem.
Any Ideas would be appreciated.
I have a procedure in my ThisAddIn class (see first code block below) that I'm trying to run from the click event of a custom ribbon button that I designed using ribbon designer (see second code). I keep getting the error message: 'Reference to a non-shared member requires an object reference.' What do I need to do to fix this? Thanks!
First block:
Public Class ThisAddIn
Public Sub fill_textboxes(ByVal control As Office.IRibbonControl)
Application.DisplayAlerts = False
For i = 1 To Application.ActiveWindow.Selection.ShapeRange.Count
Application.ActiveWindow.Selection.ShapeRange(i).TextFrame.TextRange.Text = "..."
Next
Application.DisplayAlerts = True
End Sub
Second block:
Private Sub fill_text_boxes_button_Click(sender As Object, e As RibbonControlEventArgs) Handles fill_text_boxes_button.Click
Call ThisAddIn.fill_textboxes(fill_text_boxes_button)
End Sub
You need to pass an instance of the IRibbonControl interface to the fill_textboxes sub. Use the sender argument which represents the control which fired the event:
Private Sub fill_text_boxes_button_Click(sender As Object, e As RibbonControlEventArgs) Handles fill_text_boxes_button.Click
Call ThisAddIn.fill_textboxes(sender)
End Sub
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"
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