Textchange event firing without any change in textbox contents - asp.net

I have a form with a record number, then boxes for "primary" notes and effective date.
Then I have an optional "secondary" notes and effective date box.
When someone clicks on a button to edit the primary or secondary notes, it looks to see if the other notes have changed (a session variable set to "true" fires for the "textchanged" event for the other textbox). If so, instead of enabling the textbox that matched the "edit" button, it flashes a message saying to cancel or update the other textbox's changes.
My problem is that the contents of the textbox are being viewed as "changed" when nothing is changed. If I load the record, and run a separate validation check, it verifies that the contents of the textbox match with the data originally loaded into the textbox. Then, not changing anything, when I click on the "edit" button, that separate validation comes back as no longer matching, even though the information in the session variable and the textbox are both unchanged.
Here is my validation check -
If Not Session("SN1") Is Nothing Then
sesslst = sesslst & "<p>Sec Notes match = " & (Trim(Session.Item("SN1").ToString) = Trim(txtSecondaryNotes.Text)).ToString
sesslst = sesslst & "<p>Sec Date match = " & (Trim(Session.Item("SD1").ToString) = Trim(txtSecEffDate.Text)).ToString
sesslst = sesslst & "<p>S = " & Trim(Session.Item("SN1").ToString)
sesslst = sesslst & "<p>F = " & Trim(txtSecondaryNotes.Text)
End If
lblTest.Text = sesslst
Here are the results after initial record load:
SN1 - Bill Smith (Father) 10/12/1971 Linda Smith (Mother) 7/22/1971 Boudreau W Smith (Brother) 6/7/1994
SD1 - 4/1/2014 12:00:00 AM
Sec Notes match = True
Sec Date match = True
S = Bill Smith (Father) 10/12/1971 Linda Smith (Mother) 7/22/1971
Boudreau W Smith (Brother) 6/7/1994
F = Bill Smith (Father) 10/12/1971 Linda Smith (Mother) 7/22/1971
Boudreau W Smith (Brother) 6/7/1994
(all specific data in this example has been changed, so no real personal information is being displayed)
When I click the edit button and that validation loop runs again, the "Sec Notes changed" value changes to "false," but nothing else changes.
Initially, I had the session variable for the record change set for the "TextChanged" event. When it kept setting, despite no change, I added additional validation within the change event. If both the notes and dates session variable do not match the field information, it sets another session variable as changed -
Protected Sub txtSecondaryNotes_TextChanged(sender As Object, e As EventArgs) Handles txtSecondaryNotes.TextChanged, txtSecEffDate.TextChanged
If Not ((Trim(Session.Item("SN1").ToString) = Trim(txtSecondaryNotes.Text)) And (Trim(Session.Item("SD1").ToString) = Trim(txtSecEffDate.Text))) Then
Session.Item("secondaryEditing") = True
End If
End Sub
I never get passed the check for the "secondaryEditing" session variable when I click the edit button (the lstSess() proc just lists all the session variable names and values so I can see what's being compared) -
Protected Sub btnEditPrimary_Click(sender As Object, e As EventArgs) Handles btnEditPrimary.Click
txtPolicy.Text = Trim(txtPolicy.Text).ToUpper
lstSess()
If Session.Item("secondaryEditing") = True Then
secMsg.Visible = True
Exit Sub
Else
secMsg.Visible = False
End If
So, I thought the problem, initially, was maybe with the form, loading of data, and the TextChanged event firing but not being evaluated until the button was pushed, but even when I add in the additional If-->then validation within the event, it still thinks something has changed, when the data in the field has not even been enabled, let alone manipulated.
How can I get this to honestly evaluate whether the text in the field has changed? FYI - the asp:TextBox objects have been set with and without "AutoPostBack = 'true'" with no difference in how it runs.

Save your efforts, folks. The original programmer did not import all of the necessary System and System.Web classes.

Related

How can I clear all the SAP GUI fields when I open a T-Code?

When I open a T-Code from SAP GUI, some of the fields are pre-populated from past queries. Is it possible to enter a T-Code and all the fields in the next window to be forced blank?
I develop scripts for SAP GUI and run into problems if fields already have content from prior queries.
The history cannot be disabled user-wise. Period.
Either all or nobody.
If you want to disable the history go to SAPgui options into Local data setting
The history in Windows is a simple Access MDB file but it is password-protected, so you may try to crack it and delete only your user lines but it is a bunch of work.
However, I guess the history that makes you crazy is not what I described above, but SPA/GPA parameters. Check it first
You can empty some fields with :
""
session.findById("wnd[1]/usr/ctxtRMMG1_REF-BWTAR").Text = ""
But doesn't work all the time...
My method for this is to loop through all the fields (and recursively on all children elements) and set the text value of them to an empty string.
On read-only fields it throws an error and this is why "On Error Resume Next" is necessary.
Sub Start_Clearing()
'setup SAP
If Not IsObject(SAPApplication) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPApplication.Children(0)
End If
If Not IsObject(Session) Then
Set Session = Connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject Session, "on"
WScript.ConnectObject SAPApplication, "on"
End If
Dim UserArea As Object
Set UserArea = Session.findByID("wnd[0]/usr")
Clear_Fields UserArea
End Sub
'_______________________________
Sub Clear_Fields(Area As Object)
Set SAPApplication = GetObject("SAPGUI").GetScriptingEngine
Dim Obj As Object
Dim NextArea As Object
On Error Resume Next
For i = 0 To Area.Children.Count - 1
Set Obj = Area.Children(CInt(i))
If Obj.ContainerType = True Then
If Obj.Children.Count > 0 Then
Set NextArea = SAPApplication.findByID(Obj.ID)
Clear_Fields NextArea
End If
End If
Obj.Text = ""
Next i
End Sub

Button on click event disable button after 5 times it was clicked

I am fairly new to VB.NET. I feel like I did the hard parts and struggling with the easy one! I googled it before coming here but still struggling.
Basically I have a drop down list with all the available treatments and button next to it ( Add treatment). Every time I choose treatment from list I click on the button and it add it then bind it to gridview, the only issue is I want users to be able to add up to 5 treatments then disable the button. The question how Can I say find the number of times the button was clicked then I suppose I can just put If statement, I dont know how to find the value of the number of times the button was clicked.
Dim availableTreatment As ListItem = New ListItem
Dim count As Integer = 0
For count = 0 To 4
If count <= 4 And btnavailableTreatment ( button clicked value is what should go here) Then
availableTreatment = DDTreatmentList.SelectedItem
c.name = availableTreatment.Value
saveTreatment(c)
gvavailableTreatment.DataSource = getTreatment(c.name)
gvavailableTreatment.DataBind()
Else
btnavailableTreatment.Enabled = False
End If
count = count + 1
Next
Add this markup to your page:
<asp:HiddenField id="NumberOfTimesClickedHiddenField"
value="0"
runat="server"/>
Add this to your button click handler
'get previous value
Dim numberOfTimesClicked = Integer.Parse(NumberOfTimesClickedHiddenField.Value)
'increment value
numberOfTimesClicked += 1
'store new value
NumberOfTimesClickedHiddenField.Value = numberOfTimesClicked.ToString()
If numberOfTimesClicked >= 5 Then
btnavailableTreatment.Enabled = False
End If
Now the value will be persisted in the form data on the page.
I originally wrote this in C#, and I'm not a VB.NET programmer so I used a translator to convert it. There may be syntax errors but the general flow should be correct.

Second Dynamic DIV over writes first dynamic DIV

I have searched for almost three days now and I can't find an answer to this question. As I am somewhat new to ASP.Net I am not sure what the problem is.
Here is the situation. I have an aspx page that has a web form on it. When this form loads it has two SQL queries that execute and populate different controls.
My problem lies not with the queries but creating dynamic DIV tags and adding controls to them. If the query returns one or no records everything is fine. but if there are 2 or more records returned I only end up with the last record being displayed.
When I view the page source (from the browser) I can see the DIV tag ID that was created last, but the first DIV tag is gone. It is like the first DIV tag gets over written or something. I have no idea as to why or what is causing this.
Can anyone help please?
Here is my code:
While (incCounter <= rowCount)
DivName.ID = ("rev" & Convert.ToString(incCounter)) 'Create Div name of rev and the current counter number ex. rev1
review_comments.Controls.Add(DivName) 'Add DIV to web form
rName = (rName & Convert.ToString(incCounter)) 'Create name control name
rDate = (rDate & Convert.ToString(incCounter)) 'Create date control name
rComments = (rComments & Convert.ToString(incCounter)) 'Create comment control name
DivName.Controls.Add(New LiteralControl("<br />"))
DivName.Controls.Add(rRevByLabel)
rNameTextBox.ID = rName
DivName.Controls.Add(rNameTextBox)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(nbSpace)
DivName.Controls.Add(rDateLabel)
DivName.Controls.Add(rDateTextBox)
DivName.Controls.Add(New LiteralControl("<br />"))
DivName.Controls.Add(rCommentLabel)
DivName.Controls.Add(rCommentsTextBox)
'Assign data from query to new textboxes
rNameTextBox.Text = dtR.Rows(incCounter - 1)("reviewed_by_name").ToString()
rDateTextBox.Text = dtR.Rows(incCounter - 1)("reviewed_by_date").Date()
rCommentsTextBox.Text = dtR.Rows(incCounter - 1)("review_comments").ToString()
rName = "revName"
rDate = "rDate"
rComments = "revComments"
incCounter += 1
End While
I know all the variables are set up correctly because it shows me the last record.
What stupid thing am I doing?

Selecting a value in dropdownlist in asp.net, vb.net is code behind

I have a dropdownlist populating list of values in it in page_load .
I want to select a specific value
Me.DropDownList_LocalOfficeAssignment.SelectedValue = ct.LocalOfficeName
Me.DropDownList_LocalOfficeAssignment has list of values.
Problem is: It always pointing to first item.
i tried this
For Each item As ListItem In Me.DropDownList_LocalOfficeAssignment.Items
If item.Equals(ct.LocalOfficeName) Then
item.Selected = True
Exit For
End If
Next
DV.Dispose()
still pointing to the first item. i debugged, it should point to the last item.
ct.localoffice is containing the last item in the list. This is how i am populating the dropdown :
Dim DV As DataView = New DataView(CacheVariable.States.Tables(0))
Dim DRV As DataRowView
Me.DropDownList_LocalOfficeAssignment.Items.Clear()
DV = New DataView(CacheVariable.LocalOffice.Tables(0))
If DV.Count > 0 Then
For Each DRV In DV
Me.DropDownList_LocalOfficeAssignment.Items.Add(New ListItem(DRV("Name"), DRV("LocalOfficeID").ToString))
Next
End If
Based on lengthy comments on the question...
You're looking for the wrong value when you try to set the SelectedValue. Take a look at how you create your ListItems:
Me.DropDownList_LocalOfficeAssignment.Items.Add(New ListItem(DRV("Name"), DRV("LocalOfficeID").ToString))
When creating a ListItem, you pass it both its display text and its underlying value. In this case, you're setting them as:
Display Text = DRV("Name")
Underlying Value = DRV("LocalOfficeID")
According to your comments, the sample data looks something like this:
LocalOfficeID | Name
--------------------
1 | abc
2 | def
3 | xyz
Then, when you try to manually set the SelectedValue, you're passing it the wrong value. You're essentially trying to do this:
DropDownList_LocalOfficeAssignment.SelectedValue = "xyz"
None of the Value properties on the ListItems are "xyz". They're "1", "2", and "3". In order to set the SelectedValue, you need this:
DropDownList_LocalOfficeAssignment.SelectedValue = "3"
So this line needs to change:
Me.DropDownList_LocalOfficeAssignment.SelectedValue = ct.LocalOfficeName
On your ct object you need to get the identifier for the object, not its display name. Probably something like this (though without knowing what ct is I can't be certain):
DropDownList_LocalOfficeAssignment.SelectedValue = ct.ID
If you don't have the identifier, then you can find it on the DropDownList by searching for the display name. Something like this should work, though there may be a more elegant way to do it:
DropDownList_LocalOfficeAssignment.SelectedIndex = DropDownList_LocalOfficeAssignment.Items.IndexOf(DropDownList_LocalOfficeAssignment.Items.FindByText(ct.LocalOfficeName))
Using the identifier would be much cleaner, though.
This is usually because the DropDownList does DataBind() after you set the SelectedValue. Do you have the DropDownList.DataSourceID property set? Are you calling DataBind() later in the page lifecycle?

Changing the properties of multple controls with similar IDs using a loop VB.net

I have an aspx web form with various inputs including a dropdown box with 1-10. When the form is submitted a new panel is visible that has 10 rows of static textbox and label controls. These controls are all set to visible=false by default.
What I want is based on the number selected in the previous dropdown box, that is how many rows of controls I want to change to visible=true. The IDs for these controls are the same for each row apart from the last character which is to reflect what row they belong to. So row 1 would have the following:
ticketNum_Lbl_1
your_res_Txt_1
title_Txt_1
firstname_Txt_1
surname_Txt_1
ticketNum_Txt_1
What I wanted was a simple loop that would check the number at the end of the control's ID and compare that to the number selected in the dropdown.
For clarity the dropdown list is for a user to select how many seats at a table they would like to book, the following screen would let them allocate names to the seats they are booking.
I have tried several things but am still obviously not getting it, although it might be something along the lines of:
Dim rowsNeeded As Integer = number_of_tickets_Ddl.SelectedValue
For a = 1 To rowsNeeded
Me.Controls("ticketNum_Lbl_" & a).Visible = True
Me.Controls("your_res_Txt_" & a).Visible = True
Me.Controls("title_Txt_" & a).Visible = True
Me.Controls("firstname_Txt_" & a).Visible = True
Me.Controls("surname_Txt_" & a).Visible = True
Me.Controls("ticketNum_Txt_" & a).Visible = True
Next
But this comes up with an error as the controls reference an index (integer) rather than a control's name or ID (it seems?).
Any help appreciated.
You should use FindControl
Me.FindControl("ticketNum_Lbl_" & a).Visible = True

Resources