ie
<Value>123456 </Value
thanks
markif you merely use Trim(value)
or myVar.Trim
--
this will assure you have no white space at either end
Hi,
TryString.Trim Method
HTH
TryString.Trim Method
HTH
In my code the value of strWebService is initially "2 " (that is the number two followed by a space). I then use trim to eliminate the space:
strWebService = readHtmlPage(strTMQuery)
strWebService = Trim(strWebService)
Select Case strWebService
Case "0"
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case "1"
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case "2"
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select
MikeHello -
Perhaps you might want to do a conversion to an integer for the case statement?
good luck
take care
tony
I added the following line before my select statement:
Dim intWebService As Integer = CInt(strWebService)
I then removed the double quotes from my case expressions and ran the code but still got the ELSE statement. VB doesn't require BREAK does it?
did you trying doing a response.Write(intWebService) right before the case statement so you can verify the value?
response.write("service =" & strWebService & ".")
Take note of the spaces and period. Should be
service =2.
My code now reads like this (I added the = signs to the label just to make sure the TRIM did its job...)
strWebService = readHtmlPage(strTMQuery)
strWebService = RTrim(strWebService)
Dim intWebService As Integer = CInt(strWebService)lblTest.Text = "=" & intWebService.ToString & "="
lblTest.Visible = TrueSelect Case strWebService
Case 0
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case 1
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case 2
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select
I still get the ELSE... Plus, my label does infact read 2... I don't get what I could be doing wrong...
Your select Statement is still referring to strWebService... Change it to intWebService...
Ha ha, good call. It works. Thanks guys. Strings in SELECT CASE statements SUCK!
I want to pull every name value pair out of the querystring in one string.
Thanks!
mike123You may try "Request.QueryString".
No luck
Anything else ?
Thanks!
mike123
I think Request.ServerVariables("QUERY_STRING") will return what you are after?
Simon
I have a page that sends the value of a textbox in a form through GET.
My next page is supposed to grab that value, and put it in a variable. This is what I have for my next page:
1<%@dotnet.itags.org. Import namespace="System.IO"%>2<html>
3<head>
4<title>Uploading a File</title>
5678<script language="VB" runat="server">
9Dim strPath
10 strPath = Request.QueryString("path")
11
12 Dim savePath As String = StrPath
13Sub Upload_Click(source As Object, e As EventArgs)
1415 If Not (uploadedFile.PostedFile Is Nothing) Then
16 Try
17 Dim postedFile = uploadedFile.PostedFile
18 Dim filename As String = Path.GetFileName(postedFile.FileName)
19 Dim contentType As String = postedFile.ContentType
20 Dim contentLength As Integer = postedFile.ContentLength
2122 postedFile.SaveAs(savePath & filename)
23 message.Text = postedFile.Filename & " uploaded" & _
24 "<br>content type: " & contentType & _
25 "<br>content length: " & contentLength.ToString()
26 Catch exc As Exception
27 message.Text = "Failed uploading file"
28 End Try
29 End If
30End Sub
31</script>
32
33</head>
34<body>
35
36<form id="Form1" enctype="multipart/form-data" runat="server">
37 Select File to Upload:
3839 <input id="uploadedFile" type="file" runat="server">
40 <p>
41 <input type=button id="upload"
42 value="Upload"
43 OnServerClick="Upload_Click"
44 runat="server">
45 <p>
46 <asp:Label id="message" runat="server"/>
47</form>
48
49</body>
50</html>
I get a "declaration expected" on line 10. Any Ideas why?
A simle fix is to move both lines
Dim strPath as String = Request.QueryString("path")
Dim savePath As String = StrPath
to the top of Sub Upload_Click.
The actual error is that line 9 is not complete with a type declaration.
Dim strPathAs String
Also, you don't seem to need both strPath and savePath.
Dim savePath As String = Request.QueryString("path")should be enough
Gunteman, I must respectfully disagree. If you put
Dim savePath As String = Request.QueryString("path")
outside of Sub Upload_Click, you get the following exception:
"Request is not available in this context."
However, removing strPath does make sense.
Thanks to both of you. I still got a problem even after doing that, but adding "Context." before "Request" cleared things up.
louis210:
Gunteman, I must respectfully disagree. If you put
Dim savePath As String = Request.QueryString("path")
outside of Sub Upload_Click, you get the following exception:
"Request is not available in this context."
Quite right!
Weird situation here. I have this label:
<asp:label id="lblDepositDue" runat="server" />
lblDepositDue.Text = "Deposit Due Upon Booking: " & String.Format("{0:c}", intDepositDue.ToString)Deposit Due Upon Booking: 4999
...instead of like this which SHOULD be the output:
Deposit Due Upon Booking: $4,999.00
What is going wrong?
Thanks.....MikeHow about something like this:
lblProductCost.Text = Format(intProductCost, "#,##0.00")
When I try:
lblDepositDue.Text = "Deposit Due Upon Booking: " & Format(intTotalTourCost.ToString, "#,##0.00")
It comes out like this:
Deposit Due Upon Booking: #,##0.00
:-/
Hi,
as was said, do not call ToString for the integer argument passed to the Format function (it was same problem with your original code):
Instead of:
Format(intTotalTourCost.ToString, "#,##0.00")
Format(intTotalTourCost, "#,##0.00")
In your original code following would have worked:
String.Format("{0:c}",intDepositDue)
Thank you very much for the clarification. I was under the (incorrect) assumption that String.Format required that the value passed to is was in string format already. I wasn't aware of any conversion to string simply by formatting.
Thanks again!
Mike
Sub LoadInventory()
Connect()
Dim strQuery As String = "SELECT Type, Number FROM Inventory WHERE type = 'squares'"
Dim dbComm As New OLEDBCommand(strQuery, objConnection)
Dim reader As OLEDBDataReader = dbComm.ExecuteReader()
reader.Read()
txtAmount.Text = reader.GetString(1)
reader.Close()
Disconnect()
End Sub
Sub btnChange_Click(ByVal Sender As Object, ByVal E As EventArgs)
UpdateInventory()
LoadInventory()
End Sub
Private Sub UpdateInventory()
Dim strSQL As String = "UPDATE Inventory SET Number = " & txtAmount.Text & " WHERE Type = 'squares'"
Connect()
Dim dbComm As New OLEDBCommand(strSQL, objConnection)
dbComm.ExecuteNonQuery()
Disconnect()
End Subinstead of
Dim strSQL As String = "UPDATE Inventory SET Number = " & txtAmount.Text & " WHERE Type = 'squares'"
Dim strSQL As String = "UPDATE Inventory SET Number = " & Convert.ToInt32(txtAmount.Text) & " WHERE Type = 'squares'"
Jeff
Jeff,
Thanks for your reply. That however didn't work. Could it be the way I have my access database setup?
Jeremy
Jeff,
Does it work when you try putting in a static value for txtAmount.Text such as this:
"UPDATE Inventory SET Number =1 WHERE Type='squares'"
If it does work like that, then try doing this:
Try
Dim dbComm As New OLEDBCommand(strSQL, objConnection)
dbComm.ExecuteNonQuery()
Catch dbException As Exception
Response.Write(dbException.ToString())
End Try
Tell us what the exception is. Besides, it is always good practice anyway to put database queries inside a try statement - there are just way too many things that could go wrong to not catch those errors.
Aaron
public bool SetCookie(string cookiename, string cookievalue, int iDaysToExpire) //create the cookie
{
try
{
HttpCookie objCookie = new HttpCookie(cookiename);
Response.Cookies.Clear();
Response.Cookies.Add(objCookie);
objCookie.Values.Add(cookiename, cookievalue); // adding the value to the cookie
DateTime dtExpiry = DateTime.Now.AddDays(iDaysToExpire); //expires
Response.Cookies[cookiename].Expires = dtExpiry;
}
catch (Exception e)
{
return false;
}
return true;
}
public string GetCookie(string cookiename)// method which gives the value from the cookie
{
string cookyval = "";
try
{
cookyval = Request.Cookies[cookiename].Value;
}
catch (Exception e)
{
cookyval = "";
}
return cookyval;
}
protected void Page_Load(object sender, EventArgs e)
{
String t, s,t1;
int i = 0;
s = "";
t = "";
t = GetCookie("test");//reading the cookie
//removing the name and getting the value
try
{
lbl1.Text = t; //
t1 = t.Remove(0, 9);
i = Int32.Parse(t1);
i = i + 1; //the value is modified
}
catch (Exception w) { lbl3.Text = "Convert isnt working."; }
s = Convert.ToString(i);
//writing the new value in the cookie
SetCookie("test", s, 1);
//testing to see if the new value is written
t1 = GetCookie("test");
lbl2.Text = s;
lbl3.Text = t1;
}
}What is your question, exactly? This code re-sets the cookie each time it runs. It seems to return exactly what you're setting it to ("test=0"). (Is that the value that you want it to have?)
Hey all,
I'm very much new to ASP and ASP.net, and I'm having difficulties in figuring out to get ASP.net to properly output the value of a form field in a vb script. The field in particular is one that contains a two-letter abbreviation of a state (E.g. if the visitor selected California, the value of the field would be CA). This normally works fine, but when a visitor selects Indiana, that's where ASP.net returns nothing. I can see that ASP.net recognizes IN as VB code, I'm just not sure how to force it to just print IN.
Here's a snippet of the code:
obj.OrigZipPostal = Request.Form("vendorpostal" & i)
obj.OrigStateProvince = Request.Form("vendorstate" & i)
Thanks for helping a newbie out :D
You need to convince vb.net that you are using a string and not a command, you could try CStr() or use quotes...
Hope that this helps.
Use
obj.OrigStateProvince = CStr(Request.Form("vendorstate" & i))
Thanks
I am writing a form with one value being a total of a couple other values from my page. I put this in a read-only textbox so it can't be changed, and when I change the other boxes values, the JavaScript automatically changes this value. However, when I generate the e-mail I use textboxTotalSpace.text to make it appear in my email, but this will only display the original value, and not the new one.
Does anyone know how I fix this?
Thanks.
TextBox server control will not pick up the changed values (during LoadPostData()) if the textbox is set to read only. Check this link for a fix:
http://aspadvice.com/blogs/joteke/archive/2006/04/12/16409.aspx
Hope this helps,
Vivek
Thanks Vivek, but I am unsure where I am supposed to add theTextBox1.Attributes.Add("readonly","readonly")
That should go in the Page_Load event.
protected void Page_Load(object sender, EventArgs e)
{
// add the javascript attributes
TextBox1.Attributes.Add("readonly", "readonly");
}
Thanks
Because you are changing data at client side using java script....
You can put this in the Page Load method.
suresh modiya:
Because you are changing data at client side using java script....
Changed text box value client side WILL show up in the server code behind because textbox implements IPostBackDataHandler interface and it loads its value from the forms POST data in the LoadPostBackData() method.
Its only when it is set to readonly that this data load will not work on postback, hence the alternative.
Vivek
I've got problem with DropDownList, because when I change values, I've still got the first value of List.
So, how to set new selected value of DropDownList?I guess you have the following code concept in your page: "on a page_load, retrieve the data from a database or some other source and bind it to the control". This is right but incomplete. In fact Page_Load is fired also on a postback, so when a user selects something in the dropdownlist and the page is posted back (automatically or manually) to the server, the Page_Load is executed again. In order to execute the binding code only when needed, use this skeleton of code:
if (!Page.IsPostBack) {
//do the binding
}
//do other things that are not affected by a postback.Now, you're rebinding the controls every time the page is loaded; this code will perform the binding only when no postback is done (thus, only on the first request to the page).
Great Thanks
Now everything is working :)