I've deployed my ASP.NET application today. It's a web application (I am using forms, etc.). I was happy with all my functionalities. For example, I had part of the of the code that says
if c.results = " " then MsgBox("Error! No record was returned)
Then I clear all my text boxes.
That MsgBox was working when I was running my application locally, but now that I've deployed it I get a server run error! I read some similar posts that said MsgBox is not supported with web applications, but all their answers were with JavaScript. I am not familiar with it, but I don't understand how to put my JavaScript in my Visual Basic class instead of where I am calling the MsgBox- is there a way fixing the above issue with VB.NET code?
Here is the code:
Dim results = customer.getCustomerDetails(txtCustomerNumber.Text, txtDOB.Text)
If (results.customerNumber = "") Then
Response.Write("<script>alert('Customer record not found')</script>")
txtCustomerNumber.Text = ""
txtDOB.Text = ""
Else
( Do the other stuff)
End if
MsgBox is server side so it can't show up to the client which is only seeing the client side of the ASP.NET webform, hence use the following if you want to access a JavaScript alert from code behind or simply alert in JavaScript:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "<script
language=JavaScript>alert('your wanted message');</script>")
You can generate client code from your server side VB as such:
If c.results = " " Then
Response.Write("<script>alert('Error! No record was returned')</script>")
End If
Related
I am currently tasked with moving one of our older bits of software to a new server. The old server is running 2008 and the new server is on 2019. The code is a mixture of ASP and ASP.NET, both using VB. Unfortunately, I'm a C# developer and my VB knowledge is slight.
The main bit of the code is the older and is all in ASP and works fine on the new server. For a particular set of customers there is an add-on that is more recent and uses ASP.NET. For the new section of code to get the details of the logged in user it uses the code given in this answer. Unfortunately it seems like it is this bit of code that is failing.
We have this bit of code in our site.master.vb
ctx1 = ctx.Request.Url.Scheme
ctx2 = ctx.Request.Url.Host
dom = ctx1 + "://" + ctx2
Dim ASPRequest As HttpWebRequest = WebRequest.Create(New Uri(dom + "/arc/asp2netbridge.asp?sessVar=" + sessionValue))
ASPRequest.ContentType = "text/html"
ASPRequest.Credentials = CredentialCache.DefaultCredentials
If (ASPRequest.CookieContainer Is Nothing) Then
ASPRequest.CookieContainer = New CookieContainer()
End If
The asp2netbridge.asp file is stored in the directory one up from the directory that contains the code and the directory structure looks the same on both servers. The contents of the as2netbridge file are the the same as in the example code linked above with the addition of some extra comments.
It then calls a Stored Procedure on our database with the customer ID from session that should return the customer details as XML, but instead we get a 'Root Element is missing' Error. If I change the Stored Procedure to hard code the customer ID in it, rather than as a parameter then it works as expected.
Is there anything that I need to install on our server to get the system working correctly? Or is there anything else I need to do to get it to work?
I'm a PHP / Javascript developer having to build a "simple" script that will run on a windows desktop that transfers a scanned image to a server. By using a .vbs script I have been able to do everything I need to do except send the file to the server. I have spent the last two days googling and trying examples, but nothing seems to work. Below is the code I'm currently fighting with.
Dim objShell,UserPath,sourcePath,strURL,stream, file, fileString, HTTPSevice, body
Set objshell = CreateObject("WScript.shell")
UserPath = objShell.ExpandEnvironmentStrings("%UserProfile%")
strURL = "www.notWebsite.com/uploader.php"
sourcePath = UserPath & "\Desktop\Scanned\scanned.jpg"
set stream = CreateObject( "Scripting.FileSystemObject" )
set file = stream.getfile(sourcePath)
set fileString = file.openAsTextstream
body = fileString.readAll
fileString.close
set xmlHttp = createobject("MSXML2.XMLHTTP.4.0")
xmlhttp.open "POST",strURL,false
xmlhttp.setRequestHeader "Content-Type", "multipart/form-data"
xmlhttp.send body
msgbox xmlhttp.responseText
The code doesn't throw an error, it just sends an empty request to the server.
Like I said before, I have no experience with developing for/on/near windows, so if a visual basic script isn't the right option, please let me know and point me in the right direction. I'm willing to learn how to make this work, but I'm just stuck on how to move forward.
Thank you in advanced for your help.
Using PowerShell is 100% the way to go for my usecase. Even though I've never heard of it before this morning, I already have the script working and ready for testing.
I am having VB Script in ASPX page.I need to use that Script in codeBehind in Page _load with in a For loop,for each iteration.
My Code is :-
(.ASPX Page with VB Script. )
<script type="text/vbscript" language="vbscript" >
sub wordit()
'Opens Word application and does some process
end sub
</script>
VB Code Behind Part:-
For i As Integer = 1 To colSelRowIndex
CheckboxTemplateId = colSelRowKeys(i).ToString 'I get the ID from here
ViewState("TemplateID") = CheckboxTemplateId 'I need to send the value to the sub routines
hen()'sub
den()'sub
cs.RegisterStartupScript(cstype, csname1 & i, "wordit();", True)
Next
I need to open a word doc for an ID and another document for another ID from the loop.
Try this:
For i As Integer = 1 To 10
cs.RegisterStartupScript(cstype, csname1 & i, "wordit();", True)
Next
That second argument in that function call is looking for a unique key. This is a feature, to prevent accidentally programmatically adding the same script more than once. If you want to do it on purpose, you need a unique key each time.
But that you want to do this at all indicates a possible fundamental misunderstanding about what's going on. While your server code (including Page_Load) is running, your client page in the web browser doesn't exist. The purpose of the server code is always to generate an html response to web request. The server code can never directly manipulate a page DOM.
Obviously this is true for a first request to a page in session: the server must first generate the initial page to send the client. But even on subsequent postbacks, the browser will destroy the prior instance of a page. The server must rebuild the entire page from scratch. Every. Time. While this happens, the page you're looking at in your browser window is only a sort of after-image. The browser has already destroyed any prior DOM, and is waiting for the server to supply a whole new set of HTML.
I also wonder at your use of vbscript, rather than javascript. Using vbscript pretty much guarantees you're page will only work with Internet Explorer.
Is there any kind of online "quick" asp/vbscript test tool? It's a pain to load up a test page, put all the stuff in, when I just want to test some ASP VBScript.
Yes, they are called .vbs files. These files are plain text files with a .vbs extenstion. You can run them from the command line. There are some minor differences, just google vbs or WSCript.
One of the most annoying issues is you cannot use response.write instead you use WScript.Echo. This displays the result in a windows style popup messagebox. So, if you use it in a loop to display values, you will have to close the box once for each value that is displayed. Can be a pain. I just contcatonate the results and display one message.
For example save the below code as myloop.vbs
Dim strMsg
Dim i
strMsg = ""
for i = 1 to 10
strMsg = strMsg & CStr(i) & vbCrLf
next
WScript.Echo strMsg
Double-click on myloop.vbs and it runs.
This is a pretty cool way to test out a concept without having to create an asp page and load it on the server.
I realize this isn't a very good/correct answer, but I typically use VB6 (Visual Studio 6) as a quick interactive debuggable VBScript-equivalent testbed. Some syntax is different (CreateObject), and you need to add certain references to your "Default" testing project, but it does allow me to answer any question about type conversions etc within a few seconds (VB6 startup time + type/paste time + F5) rather than the few minutes it will take me to set up an ASP page, and even worse start up ASP debugging, which as of VS2008 and Windows 2003 is just a huge pain.
I am trying to make a small, data-driven widget that is populated with data from a database on the fly. I can load it initially just fine, but when the index of an ASP DropDownMenu is changed, the widget returns a 404.
This could be a symptom of how I am using the Javascript, or how I am using the ASP. I honestly don't know for sure.
Javascript: http://pastebin.com/f127d6b84
ASP: http://pastebin.com/f38c73708
VB.NET codebehind: http://pastebin.com/f7881a903
If the postback is returning 404, I'd look at the url that you're sending the postback to.
http://webwidgetstest.reeceandnichols.com/rDeskWidgetMLSt.aspx?agentname=jendene
Also your widget has some security issues going on, namely SQL Injection.
Dim SelectString As String = "select
ListingNumber, ListingSearchHitCount,
ListingDetailHitCount,
VirtualTourHitCount from
FNIS.dbo.ListingHitCountCurrent,
RAN.dbo.Heartland_Residential where
Heartland_Residential.LIST_AGENT_1_ID
= '" & Request("agentname") & "' and Heartland_Residential.MLS_Number =
FNIS.dbo.ListingHitCountCurrent.ListingNumber
and Heartland_Residential.Status =
'A'"
This inline SQL statement is not parameterizing the Request("agentname") field.