catch an event from a message box in asp.net - asp.net

So my boss gaved me the project of adapting a vb.net aplication into asp.net but i never worked with asp.net before and im learning from the internet so dont blame me xD. So in my page after the login i wanted a msgbox to pop up saying "welcome" or something like that, and i managed to come across this code
MessageBox("Welcome to wrox forum")
Private Sub MessageBox(ByVal msg As String)
Dim lbl As New Label
lbl.Text = "<script language='javascript'>" & Environment.NewLine & _
"window.alert('" + msg + "')</script>"
Page.Controls.Add(lbl)
End Sub
so this works fine but after the message (after the user press the ok button) i would like to redirect the user to other page but i dont know how to create the event wich will trigger after the user press "ok" any ideas?
thank you,

The code after alert will execute once the dialog is closed. So just add your code at the end of the script, e.g.,
lbl.Text = "<script language='javascript'>" & Environment.NewLine & _
"window.alert('" + msg + "');" & Environment.NewLine & _
"document.location = 'https://www.GoHere.com';</script>"

Related

GetCurrentUserName() is causing crash in MS Access 2010

I am running Windows 7 Professional. I have an MS Access frontend to an MS Access backend. The form that opens at the start of opening the frontend causes the app to crash.
Here is the code:
Private Sub Form_Open(Cancel As Integer)
Dim strMyDir As String
Dim intPos As Integer
Dim rst As dao.Recordset
Dim strSQL As String
Dim rstWhatsNew As dao.Recordset
DoCmd.ShowToolbar "Database", acToolbarNo
DoCmd.ShowToolbar "Toolbox", acToolbarNo
DoCmd.ShowToolbar "Form View", acToolbarNo
If Application.GetOption("ShowWindowsInTaskbar") = -1 Then
Application.SetOption "ShowWindowsInTaskbar", 0
End If
If DLookup("Locked", "luLockOut") <> 0 Then
MsgBox "Database is being worked on. Please try back in a couple minutes.", vbInformation, " "
DoCmd.Quit
Else
strSQL = "Select * From tblLastLogins Where UserName = '" & GetCurrentUserName() & "'"
This is where I have traced the error to: GetCurrentUserName()
Set rst = CurrentDb.OpenRecordset(strSQL)
With rst
If Not .EOF Then
.Edit
strSQL = "Select WhatsNewID From tblWhatsNew Where DateAdded >= #" & !LastLoginDate & "#"
Set rstWhatsNew = CurrentDb.OpenRecordset(strSQL)
While Not rstWhatsNew.EOF
DoCmd.OpenForm "frmWhatsNew", , , , , acDialog, rstWhatsNew!WhatsNewID
rstWhatsNew.MoveNext
Wend
rstWhatsNew.Close
Set rstWhatsNew = Nothing
Else
.AddNew
!UserName = GetCurrentUserName()
End If
!LastLoginDate = Now()
!IsLoggedIn = -1
Me.txtLastLoginID = !LastLoginID
.Update
.Close
End With
Set rst = Nothing
DoCmd.OpenForm "frmPrivacyNote"
Debug.Print Me.txtLastLoginID
End If
I need to track the username, so if GetCurrentUserName() is outdated, what is the current syntax?
Further follow up. I could not find data on Bing for GetCurrentUserName(), for good reason. It is a function within a MOD, so I need to figure out why the MOD is not getting called, or is malfunctioning.
After further delving, I found a Referenced MDB that has another function created by one of our users that is the cause of this error.
This is currently not an issue of MS Access working incorrectly. It is an issue with user created code.
GetCurrentUserName() is not defined by Access, so you should have looked at (and posted) its code.
If you are looking for the Windows user name, use this function:
Public Function GetUserName() As String
' GetUserName = Environ("USERNAME")
' Environ("USERNAME") is easily spoofed, see comment by HansUp
GetUserName = CreateObject("WScript.Network").UserName
End Function
Source
The link below would suggest that
CurrentUser()
is the function
CurrentUser()
Andre, thank you very much for the insight! I found this link:
http://www.codeproject.com/Articles/1422/Getting-User-Information-Using-WSH-and-VBScript
Dim objNet
On Error Resume Next
'In case we fail to create object then display our custom error
Set objNet = CreateObject("WScript.NetWork")
If Err.Number <> 0 Then 'If error occured then display notice
MsgBox "Don't be Shy." & vbCRLF &_
"Do not press ""No"" If your browser warns you."
Document.Location = "UserInfo.html"
'Place the Name of the document.
'It will display again
End If
Dim strInfo
strInfo = "User Name is " & objNet.UserName & vbCrLf & _
"Computer Name is " & objNet.ComputerName & vbCrLf & _
"Domain Name is " & objNet.UserDomain
MsgBox strInfo
Set objNet = Nothing 'Destroy the Object to free the Memory

Toastr Alert Asp.Net Vb

Im trying to do some alert messages on a web form in visual studio vb, but it keeps giving me this error when i try and code it dynamically in the action method
"only content controls are allowed directly in a content page that contains content controls"
i have left the old code in where it just produces a label error message into the HTML
getting a blue wave line underneath this line
popupScript = "<script language='javascript'>" + "showErrorToast();" + "</script>"
jquery function
<script type="text/javascript">
function showErrorToastr() {
toastr.warning('Please enter at least 3 characters of the organisation name')
}
Vb Action method when cancel button its clicked
Protected Sub btnSelect0_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim popupScript As String = ""
If txtorgname.Text = "" Then
lblerror.Text = "Please enter at least 3 characters of the organisation name"
txtorgname.Focus()
popupScript = "<script language='javascript'>" + "showErrorToast();" + "</script>"
ElseIf Len(txtorgname.Text) < 3 Then
lblerror.Text = "Please enter at least 3 characters of the organisation name"
txtorgname.Focus()
ElseIf Len(txtorgname.Text) > 50 Then
lblerror.Text = "Organisation name too long. Max 50"
txtorgname.Focus()
Else
BindData()
End If
End Sub
showErrorToast does not exist in your example, but showErrorToastr does.
Try that change. If it doesn't work, please comment.

Publishing page from workflow

Whenever page is created or modified we want it to be published to Staging target.
For this we have Manual Activity "Create or Edit Page", then we have automatic activity "Publish to Staging" in this we have written following code, but page is not getting published when it is created or modified. Also no error is shown how to debug where things are going wrong.
' Script for Automatic Activity Content Manager Workflow
Set oTDSE = CreateObject("TDS.TDSE")
Call oTDSE.Initialize
Set ObjCurrentItem = CurrentWorkItem.GetItem(3)
sDestinationServer = "tcm:0-2-65538"
Set oPage = oTDSE.GetObject(ObjCurrentItem.ID, 3)
Call oPage.Publish(sDestinationServer, True, True, True)
FinishActivity "Publish to Staging for Review"
set oPage = Nothing
set ObjCurrentItem = Nothing
set oTDSE = Nothing
Since you mentioned this is your first workflow implementation, here are some other basics to try/look for. Since this is a Page Workflow, I'm assuming that the Structure Group that you are creating/editing the page in has already been associated to a Workflow Process Definition in that SG's workflow tab.
Create a new page (or edit a page) in the SG with the Workflow process definition set.
Verify that the Page is locked and in Workflow. From the Shortcuts section, goto "My Tasks". You should see your page there. If not, then the SG is probably missing the Process Definition.
Right click the page from "My Tasks" and click "Finish Activity". This should finish your Manual Step and send it to your Automatic Activity. That Activity should then execute the script, which will publish the page and then finish the automatic activity, sending the workflow process to your next step.
Verify that the Page has been published (check publishing queue).
If the page has not been published, go to the page and check its status. If an error happens during an Automatic Activity, the workflow item will be "suspended" and stuck on that activity. If you see this, you can get details of the error from the Event Log under Source "Workflow Script".
If following the above, and the workflow item is moving along the workflow process correctly (getting past your automatic activity without error and to your next activity) and you are still not seeing it being published, then verify what Nuno suggested.
Also note that you don't have to open the page using the TDSE object as you already have it opened via the CurrentWorkItem.GetItem() method... your script can be shortened:
Dim ObjCurrentItem
Set ObjCurrentItem = CurrentWorkItem.GetItem()
Call ObjCurrentItem.Publish("tcm:0-2-65538", True, True, True)
FinishActivity "Publish to Staging for Review"
Set ObjCurrentItem = Nothing
As you can see this is a very old code but works to publish objects via Workflow. "This code also publishes the pages/where this items is referenced."
Apart from looking at various logs, would suggest set the clean=false and check till what point the packages are created. This will give you idea how far it has reached. Ofcourse put bit of debug messages to see if all executes well.
Sub WFPublishPages( ByRef oComponent, ByRef targets, ByRef activateBlueprinting, ByRef activateWorkflow, ByRef rollbackOnFailure, ByRef publishTime, ByRef unpublishTime, ByRef deployTime, ByRef resolveComponentLinks, ByRef priority, ByRef ignoreRenderFailures, ByRef maximumRenderFailures )
' If IsNull(publishTime) Then
' publishTime = 0
' End If
' If IsNull(unpublishTime) Then
' unpublishTime = 0
' End If
' If IsNull(deployTime) Then
' deployTime = 0
' End If
' If IsNull(resolveComponentLinks) Then
' resolveComponentLinks = True
' End If
' If IsNull(priority) Then
' priority = PublishPriorityNormal
' End If
' If IsNull(ignoreRenderFailures) Then
' ignoreRenderFailures = false
' End If
' Is IsNull(maximumRenderFailures) Then
' maximumRenderFailures = 0
' End If
Dim Debugstring
Debugstring = ""
Dim oLRF
Set oLRF = TDSE.CreateListRowFilter()
Call oLRF.SetCondition("ItemType", ItemTypePage)
Call oLRF.SetCondition("OnlyLatestItems", True)
Dim oXML
Set oXML = CreateObject("MSXML2.DOMDocument.6.0")
Call oXML.setProperty("SelectionNamespaces", "xmlns:tcm=""http://www.tridion.com/ContentManager/5.0"" xmlns:xlink=""http://www.w3.org/1999/xlink""")
Call oXML.loadXML(oComponent.Info.GetListUsingItems(XMLListID, oLRF))
Dim oNode
Dim oPage
Dim strPageID
Debugstring = Debugstring & " DUBUG: ComponentID " & oComponent.ID & vbCrLf
For Each oNode In oXML.selectNodes("/tcm:ListUsingItems/tcm:Item")
strPageID = oNode.selectSingleNode("#ID").text
Debugstring = Debugstring & " DUBUG: PageID " & strPageID & vbCrLf
Set oPage = TDSE.GetObject(strPageID, OpenModeView )
Debugstring = Debugstring & " DUBUG: oPage.Title "
Debugstring = Debugstring & oPage.Title
Debugstring = Debugstring & vbCrLf
Call oPage.Publish(targets , activateBlueprinting, activateWorkflow, rollbackOnFailure, publishTime, unpublishTime, deployTime, resolveComponentLinks, priority,ignoreRenderFailures,maximumRenderFailures )
Call WriteLog("Publish Page: " & oPage.Title & " for component " & oComponent.Title & " - renderTime is " & publishTime & " - deployTime is " & deployTime)
Set oPage = Nothing
Set oNode = Nothing
Next
Set oXML = Nothing
Set oLRF = Nothing
Thanks
Vin
Here's a few things you can test:
Run the publisher in debug mode (stop the service, open a command prompt, run c:\Program Files (x86)\Tridion\bin\TcmPublisher /debug) and check for errors
Try publishing the page from the "My Tasks" view
Check if your page's current approval status is higher or equal than the Publication Target's "Minimum approval Status"

Display Message to user and then abandon Session

I have added Two Factor Authentication to my Mobile ASP.Net Web App. When the user successfully enters their User Name and Password then a pin number is emailed to their email address which is stored in the database. The issue I am having is that after notifying the user that they don't have an email defined and then reload the login page but my code isn't notifying the user rather it is just reloading the Login.aspx page:
Private Sub GeneratePin()
Dim r As New Random(System.DateTime.Now.Millisecond)
_Pin = CStr(r.Next(1000, 99999))
_email = CIAppGlobals.CurrentUser.UsrContactEmail
With lblPin
.Text = "PIN has been emailed to the you please check your email now."
End With
If Not String.IsNullOrEmpty(_email) Then
Dim Message As String = " Your Mobile PIN number is " & _Pin & vbNewLine & "From IP Address: " & CIAppGlobals.AppSettings.ClientIP
Tools.SendEmail(CIAppGlobals.CurrentUser.UsrContactEmail, "Mobile App - Two Factor Authentication", Message)
Else
Dim sText As String = "Please contact the Administrator You do not have an email address defined within Application."
'DirectCast(HttpContext.Current.Handler, System.Web.UI.Page).ClientScript.RegisterStartupScript(Me.[GetType](), "test", "alert('" & sText & "')", True)
Response.Write("<script>alert('" & sText & "');</script>")
Thread.Sleep(5000)
'Session.Abandon()
'FormsAuthentication.SignOut()
Response.Redirect(ParentFolder & "/Login.aspx")
End If
End Sub
Your call to Response.Redirect() is causing anything you output not to be displayed. You need to remove that, then output a link or some javascript to go to the login page.
Also: you need to remove the call to Thread.Sleep(). That is causing a needless delay and keeping an asp.net thread busy doing nothing. It's not doing what you think it is...

How to Validate a textbox+dropdowns in vb for a asp.net form

Previous question which links onto this and has any addition code ref should I forget to link any, I have set it up to email me should someone submit this form and an error occur and right now should that occur for most integer or datetime fields if they fail to validate then it will show me which fields in the email failed and what was input into them.
Problem I'm having now is to validate the drop downs and the textboxs in a similar way to what I with integer and datetime fields so I can display those also in the email in case they error.
present integer and datetime validation
Catch ex As Exception
lblInformation.Text = ("<h4>Unable to save data in database</h4>" + vbNewLine + "The error was '" + ex.Message + "'" + vbNewLine + vbNewLine + vbNewLine + "The SQL Command which falied was:" + vbNewLine + "<strong>" + mySQL + "</strong>" + vbNewLine).Replace(vbNewLine, "<br />" + vbNewLine)
Dim dtb As DateTime
If Not DateTime.TryParse(DateOfBirth, dtb) Then
strEMessageBody.Append("<strong>Date Of Birth:</strong> " & DateOfBirthYear.SelectedItem.Value & "-" & DateOfBirthMonth.SelectedItem.Value & "-" & DateOfBirthDay.SelectedItem.Value & vbCrLf)
strEMessageBody.Append("<br/>" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab)
End If
Dim iao As Integer
If Not Integer.TryParse(AnyOther, iao) Then
strEMessageBody.Append("<strong>Any Other:</strong> " & rblAnyOther.Text & vbCrLf)
strEMessageBody.Append("<br/>" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab)
End If
then below the final validation I have the Dim for the email setting but that I sorted out in the other question.
The problem is much earlier in the page I have
Sub Upload_Click(ByVal source As Object, ByVal e As EventArgs)
If (Page.IsValid) Then
Dim Name As String
Which prevents me just using there names as shown above where I would instead call them something else but that doesn't work with strings so my main issue is having some bit of code to check if the strings are valid and for the dropdowns which would either work but always show the data in the email or would hiccup in the code,
Dim imd As Integer
If Not Integer.TryParse(dept, imd) Then
strEMessageBody.Append("<strong>Department:</strong> " & dept.Text & vbCrLf)
strEMessageBody.Append("<br/>" & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab)
End If
below was how it had been setup to record the department
Department = dept.SelectedItem.Value
Department = Replace(Department, "'", "''")
Summary:- Need vb code to validate if strings and dropdowns are valid and the use of try/catch block is another possible solution but I wasn't able to figure out how to implement validation for that either.
Log your values into your database. Setup a logging table called "tblLog" or something else. Record the value of ex.Message or possibly even InnerException (if it exists).
Going hand in hand with Matt's answer, there is a tool that can help you with automatically logging errors to a DB.
It's called ELMAH.
EDIT
Here are 2 validations that you might want to use:
Dim s As String = "some user input in here"
If [String].IsNullOrEmpty(s) Then
' Watch out, string is null or it is an empty string
End If
Dim cb As New ComboBox()
If cb.SelectedItem Is Nothing Then
' Watch out, combo has no item selected
End If
NOTE ComboBox is a WinForm control in this example, but the idea is the same for the ASP.NET counterpart
Since everybodies given up trying to find a solution then I'm just gona close this topic with this post as the answer.

Resources