I have a asp vb page that holds store hours. I'm supposed to add a textbox that has a list of people's emails in it. The emails come from a database, someone else wrote the code for that. But I need to be able to fill a textbox with these emails and have the textbox editable so someone can change or add new emails. So how do you get it so the textbox automatically fills up with the emails? I have a textbox on the asp page. And I have some code on the vb page to try to fill it but nothing shows up in textbox. Please help, I'm very new at this!
Asp:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="label1" Text="List Of Emails" runat="server" /> <br />
<asp:TextBox ID="emailBox" TextMode="MultiLine" runat="server" />
<br/><br/>
<asp:Button Text="Save" runat="server" />
<asp:Button Text="Cancel" runat="server" />
</div>
</form>
</body>
</html>
VB:
Partial Class KioskEmailUpdate
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Dim tempstoreID As Integer = 101
Dim ds As DataSet
Dim emailList As String = ""
ds = DBUtility.GetKisokAlertEmails(tempstoreID)
If Not ds Is Nothing AndAlso ds.Tables.Count > 0 And ds.Tables(0).Rows.Count > 0 Then
For Each dr In ds.Tables(0).Rows
emailList = dr("EmailList")
Next
End If
Dim seperatedEmailList() As String = Split(emailList, ";")
Dim counter As Integer = 0
For Each email In seperatedEmailList
emailBox.Text = emailBox.Text + email
counter = counter + 1
Next
Catch ex As Exception
Dim tempstoreID As Integer = 101
LogUtility.LogMessage("Error in getting and parsing email list from database. " & ex.ToString, "I", tempstoreID)
End Try
End Sub
End Class
You keep overwriting the variable emailList. Therefore, when you attempt to split it, you will only get one email address.
Change:
emailList = dr("EmailList")
To:
emailList &= dr("EmailList").ToString & ";"
Related
What I am attempting to achieve is basically this:
user clicks on save as button
dialog "pop-up" shows that has report categories and name entry
user enters a name, or selects category which loads old reports
backend will get the values from dialog and use those to update reports in database
My issue is that when I fire the MyTreeView.SelectedNodeChanged event, I am redirected to the aspx page that I'm showing in my dialog pop-up. Is there anything I can do to prevent this, or contain the postback? I included my code, but I'm guessing this will be something I will have to account for in aspx?
Here's some code:
ReportSave.aspx -- in dialog window
<%# Page Language="VB" AutoEventWireup="false" CodeFile="ReportSave.aspx.vb" Inherits="ReportSave" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Save Report As</title>
<link href="ReportSaveStyle.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<form id="formReportSave" runat="server">
<div class="container">
<asp:Label class="report-list-title" ID="lblReportList" runat="server" Text="Report List"></asp:Label>
<asp:TreeView class="report-list-items" ID="trvReportList" runat="server"></asp:TreeView>
<asp:Label class="category-tree-title" ID="lblReportCategory" runat="server" Text="Report Category"></asp:Label>
<asp:TreeView class="category-tree-items" ID="trvCategoryView" runat="server"></asp:TreeView>
<asp:Label class="save-input-title" ID="lblReportName" runat="server" Text="Report Name"></asp:Label>
<asp:TextBox class="save-input-textbox" ID="tbReportName" runat="server"></asp:TextBox>
<asp:Button class="save-button1" ID="btnOK" runat="server" Text="OK" />
<asp:Button class="save-button2" ID="btnCancel" runat="server" Text="Cancel" />
</div>
</form>
</body>
</html>
Backend code - ReportSave.aspx.vb
Private Sub trvCategoryView_SelectedNodeChanged(sender As Object, e As EventArgs) Handles trvCategoryView.SelectedNodeChanged
Try
'Dim li As ListItem
'li = cblCategoryView.SelectedItem
Dim node As TreeNode
node = trvCategoryView.SelectedNode
' handle all categories
If node.Value.ToString.ToUpper = "NEW CATEGORY" Then
Dim strNC As String = InputBox("Enter Name for New Category", "Create Category")
If strNC = "" Then
Exit Sub
End If
If strNC.ToUpper = "NEW CATEGORY" Then
ClientScript.RegisterStartupScript(Me.GetType(), "myalert", "window.alert('You can't have a Category Called New Category. Sorry!');", True)
Exit Sub
End If
Dim conn As New SqlClient.SqlConnection(_ConnectionString)
conn.Open()
Dim cmd As New SqlClient.SqlCommand("Select recordno from Reports where ReportType = '" & strNC & "'", conn)
Dim strresult As String = cmd.ExecuteScalar
If IsNothing(strresult) Then
Dim temp As TreeNode = New TreeNode(strNC, strNC, "Images/file.png")
' Dim temp As ListItem = New ListItem(strNC, strNC)
'lvCategoryView.Items.Add(temp)
'SetSelectedListItem(lvCategoryView.Items(lvCategoryView.Items.Count - 1))
'cblCategoryView.Items.Add(temp)
trvCategoryView.Nodes.Add(temp)
FillReports()
lblReportList.Text = "Report List for Group " & trvCategoryView.SelectedValue.ToString
' cblCategoryView.SelectedValue
ClientScript.RegisterStartupScript(Me.GetType(), "myalert", "window.alert('That Report Group Already Exists');", True)
End If
cmd.Dispose()
cmd = Nothing
conn.Close()
conn.Dispose()
conn = Nothing
Exit Sub
Else
'SetSelectedListItem(li)
FillReports()
lblReportList.Text = "Report List for Group " & trvCategoryView.SelectedValue.ToString
'cblCategoryView.SelectedValue.ToString
End If
Catch ex As Exception
End Try
End Sub
Thanks for any help in advance! I am new to Web Development as well as ASP.NET. :)
I am making the assumption that you are loading this form into an iframe, and would guess that the problem lies in the implementation of the MyTreeView.SelectedNodeChanged event or the parent page itself.
Thinking outside the box, Web Forms may have alternate solutions to accomplish your objectives. The implementation of an iframe would be my least favorite. Depending on your specific requirements, these options may work better for you.
Nested Masterpages
Re-usable User Control (ascx) in overlay (popup) DIV element
Update Panel in overlay (popup) DIV element
AJAX post to Handler (ashx)
VS 2013, ASP.NET 3.5 VB.NET
Page has multiple ModalPopupExtender controls for different popups. One of these popups fills a table with CheckBoxControls and descriptions for up-selling items.
Page Code:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
[snip]
<ajax:ModalPopupExtender
runat="server"
ID="mpeUpsell"
popupControlID="pUpsell"
CancelControlID="bGoBack"
BackgroundCssClass="custBackground"
PopupDragHandleControlID="phDragUpsell"
TargetControlID="bHidden"
Enabled="True" />
<asp:Panel runat="server" ID="pUpsell" style="display:none;">
<div runat="server" class="custPopup">
<div runat="server" id="phDragUpsell">
<h3 style="text-align:center;">
<asp:Label
ID="lUpsellHdr"
runat="server"
Text="Check Out these Add-Ons" />
</h3>
</div>
<asp:Label
ID="lAddOnsText"
runat="server" />
[snip]
<asp:Table
ID="tItems"
runat="server"
style="border: 1px solid black;">
[snip] <asp:Button ID="bNext" runat="server" Text="Next --->" />
</td>
</tr>
</table>
<br />
<br />
</div>
</asp:Panel>
The table tItems is populated like so:
For Each dr As DataRow In ds.Tables(0).Rows
tr = New TableRow()
tc = New TableCell()
Dim sName As String = "cbItem_" & CInt(dr("ITEM_ID"))
Dim cb As New CheckBox()
cb.ID = sName
cb.Text = dr("ITEM_DESC").ToString.Trim
If CInt(dr("UGICheckOFF")) = 1 Then
cb.Checked = True
Else
cb.Checked = False
End If
[snip formatting]
tc.Controls.Add(cb)
tr.Cells.Add(tc)
tc2 = New TableCell()
Dim sPrice As String = String.Format("{0:C}", dr("ITEM_PRICE"))
tc2.Text = sPrice
[snip formatting]
tr.Cells.Add(tc2)
tItems.Rows.Add(tr)
Next
The table populates perfectly and shows when I use code-behind to show the mpeUpsell ModalPopupExtender.
The bNext button's handler looks like this:
Protected Sub bNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bNext.Click
If iItemArray IsNot Nothing Then iItemArray = Nothing ' get rid of it
' Handle the Next Button
Dim iCartID As Integer = -1
iCartID = CInt(Session("CartID"))
' iterate the items and add each to cart if not already in cart
iItemArray = New ArrayList()
For Each tr As TableRow In tItems.Rows
For Each tc As TableCell In tr.Cells
For Each ctl As Control In tc.Controls
If TypeOf (ctl) Is CheckBox Then
Dim cb As CheckBox = CType(ctl, CheckBox)
If cb.Checked Then
'if there are checks create array of item IDs checked.
Dim itemid As Integer = CInt(cb.ID.Replace("cbItem_", ""))
iItemArray.Add(itemid)
End If
End If
Next
Next
Next
[snip]
End Sub
When the handler is executed, tItems.Rows.Count is ZERO and the ForEach simply falls through because the table rows are gone.
It is obvious that I have missed something; I just cannot figure out what I have missed.
Thanks,
John.
The solution was to abandon the asp table because it is not stateful in this instance. Instead, I used a gridview and bound a datatable to it, and am able to retrieve the values.
Thanks.
I have a page that queries a DB and displays information for a number of printers. I have several sections that I would like to update at different intervals client-side using AJAX (at least this is best solution my research has come up with). I can get AJAX itself to work with the common "Show the time" example without any issues.
My problem is that the IDs if the sections I want to update (I've tried span, asp:label, div...> are generated with the server side code and ends up something like "Label1", "Label2"...
Every time I try to update the text inside one of these generated labels I get "'Label1' is not declared. It may be inaccessible due to its protection level". Everything is within a form tag, everything is "runat="server"". I feel like I'm just missing a setting, or a reference to something. So far I haven't been able to narrow my searching enough to get a useful answer.
I've lurked around here for years and have always been able to find a solution. This has me stumped though.
---- Example -----
The end goal is to have better control of when and how specific elements are updated. This is using the Timer tutorial demo. In my application I would be assigning IDs for the labels based on a record ID from a query (i.e. ID = "Mach" & MID)
The original code that works as posted:
<form id="form1" runat="server">
<div>
<!-- Ajax button code start -->
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Ajax - Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<!-- Ajax button code end -->
<br /><br />
<!-- Non - Ajax button code start -->
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button2" runat="server" Text="Non - Ajax - Button" onclick="Button2_Click" />
<!-- Non - Ajax button code end -->
</div>
</form>
And the Code Behind
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = DateTime.Now.ToString()
Label2.Text = DateTime.Now.ToString()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = DateTime.Now.ToString()
Label2.Text = DateTime.Now.ToString()
End Sub
It seems to me the follow should work the same way:
<form id="form1" runat="server">
<div>
<% Call Generated()%>
</div>
</form>
Code Behind:
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = DateTime.Now.ToString()
Label2.Text = DateTime.Now.ToString()
End Sub
Public Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = DateTime.Now.ToString()
Label2.Text = DateTime.Now.ToString()
End Sub
Public Sub Generated()
Dim str As String
str = "<div>"
str = str & ("<asp:ScriptManager ID=""ScriptManager1"" runat=""server"" />")
str = str & ("<asp:UpdatePanel ID=""UpdatePanel1"" runat=""server"">")
str = str & ("<ContentTemplate>")
str = str & ("<asp:Label ID=""Label1"" runat=""server"" Text=""Label""></asp:Label>")
str = str & ("<asp:Button ID=""Button1"" runat=""server"" Text=""Ajax - Button"" onclick=""Button1_Click"" />")
str = str & ("</ContentTemplate>")
str = str & ("</asp:UpdatePanel>")
str = str & ("<br /><br />")
str = str & ("<asp:Label ID=""Label2"" runat=""server"" Text=""Label""></asp:Label>")
str = str & ("<asp:Button ID=""Button2"" runat=""server"" Text=""Non - Ajax - Button"" onclick=""Button2_Click"" />")
str = str & ("</div>")
End Sub
I am learning ASP.NET 4 and i am trying to a form which the user enter details into text boxes and drop downs and then presses enter to complete form and the details go into a database in Oracle. What i would like to do is when the enter button is pressed i would like it to clear the form of anything entered and then show a message to say something like 'Thank you for your details'.
The form is working and records all the information to the database so all i need help with is clearing the form after button pressed and then to show message.
I'm not sure what code i need to show you so please ask if you do or anything else if i have not explained myself enough.
Thanks
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="StyleSheet.css" rel="stylesheet" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="navigationB">
<ul id="nav">
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
<li>Finance Help</li>
</ul>
</div>
<div id="dform">
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<h3 id="head3"><u>Please Enter Your Details:</u></h3>
Enter Your Name:
<asp:TextBox ID="nameB" runat="server"></asp:TextBox>* <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="You Must Provide Your Name" ControlToValidate="nameB"></asp:RequiredFieldValidator>
<br />
Enter Your Age:
<asp:TextBox ID="ageB" runat="server"></asp:TextBox>* <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ageB" ErrorMessage="You Must Enter Your Age"></asp:RequiredFieldValidator> <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Age Must be Between 1-99" ControlToValidate="ageB" MaximumValue="99" MinimumValue="1" SetFocusOnError="True"></asp:RangeValidator>
<br />
<br />
Male:
<asp:CheckBox ID="cbMale" runat="server" groupname="sexB" />
<br />
Female:
<asp:CheckBox ID="cbFemale" runat="server" groupname="sexB"/>
<br />
<br />
<h3 id="header3"><u>Select Hospital Department</u></h3>
<asp:DropDownList ID="DDList" runat="server" Width="201px">
</asp:DropDownList>*
<asp:DropDownList ID="DDList2" runat="server" Width="145px">
</asp:DropDownList>*
<br />
<asp:RequiredFieldValidator runat="server" ErrorMessage="You Must Select One Option" ControlToValidate="DDList"></asp:RequiredFieldValidator>
  ; <asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server" ErrorMessage="You Must Select One Option" ControlToValidate="DDList2"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="ButtonEnt" runat="server" Text="Enter"/> <asp:Button id="btnReset" onclick="btnReset_Click" runat="server" Text="Reset Form"></asp:Button>
<br />
<br />
<asp:Label ID="requiredField" runat="server" Text="(*) Denotes Required Field"></asp:Label>
<br />
</div>
</form>
</body>
</html>
My Function..
Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports System.Data
Public Class sqlFunc
Public Shared Function tableData() As DataSet
Dim oraConnect As New OracleConnection
oraConnect.ConnectionString = ConfigurationManager.ConnectionStrings("smart_dev").ConnectionString
Dim oraCommand As New OracleCommand
oraCommand.Connection = oraConnect
oraCommand.CommandType = Data.CommandType.Text
Dim lsSQL As String = ""
lsSQL = "SELECT code, description FROM ref_code WHERE domain = 'SPECIALTY'"
oraCommand.CommandText = lsSQL
Dim da As New OracleDataAdapter(oraCommand)
Dim ds As New DataSet
da.Fill(ds)
Return ds
End Function
Public Shared Function tableData2() As DataSet
Dim oraConnect As New OracleConnection
oraConnect.ConnectionString = ConfigurationManager.ConnectionStrings("smart_dev").ConnectionString
Dim oraCommand As New OracleCommand
oraCommand.Connection = oraConnect
oraCommand.CommandType = Data.CommandType.Text
Dim lsSQL As String = ""
lsSQL = "SELECT code, description FROM ref_code WHERE domain = 'CATEGORY'"
oraCommand.CommandText = lsSQL
Dim da As New OracleDataAdapter(oraCommand)
Dim ds As New DataSet
da.Fill(ds)
Return ds
End Function
Public Shared Function dataInsertTable(ByVal sName As String, ByVal iAge As Integer, ByVal sSelect As String, ByVal dList As String, ByVal dList2 As String) As String
Dim answer As String = "Y"
Dim conSmart As New OracleConnection
conSmart.ConnectionString = ConfigurationManager.ConnectionStrings("smart_dev").ConnectionString
Dim oraCommand As New OracleCommand
oraCommand.CommandType = Data.CommandType.Text
oraCommand.Connection = conSmart
Dim lsSQL2 As String = ""
lsSQL2 = "INSERT INTO TEST_JC VALUES ('" & sName & "','" & iAge & "','" & sSelect & "','" & dList & "','" & dList2 & "' , sysdate )"
oraCommand.CommandText = lsSQL2
Try
conSmart.Open()
oraCommand.ExecuteNonQuery()
conSmart.Close()
Catch ex As Exception
answer = ex.Message
End Try
Return answer
End Function
End Class
put these lines like this in your button click event after saving values in database :
nameB.Text = "";
ageB.Text = "";
...
cbMale.Checked = false;
...
and bind your dropdownlists again too and finally show your message
On submit do,
call Clear();
public void Clear()
{
txtname.text="";
txtage.text="";
}
Protected void btnsubmit_click()
{
Scriptmanager.Registerstartupscript(this, GetType(), "show your alert message","showalert()", true)
Clear();
}
Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click
ScriptManager.RegisterStartupScript(Me, [GetType](), "displayalertmessage", "Showalert();", True)
txtname.Text = ""
txtage.Text = ""
dropdownlist.Text = ""
End Sub
This will Help you.
I am new to web building. I have the following listbox on the page. The page is enabled view state.
<asp:ListBox ID="ExamsList_ListBox" runat="server" DataTextField="Namee" viewstate="enabled"
DataValueField="ID" AutoPostBack="true" Height="213px" Width="152px"
ViewStateMode="Enabled" />
The data is data bind at run time. I ma able to see the list, but the listbox.selectedindex always results in "-1" value only even though I click the 10th one in box. could you please tell me what is wrong.
Here is the page code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body >
<form id="form1" runat="server">
<div>
<div>
<asp:ListBox ID="ExamsList_ListBox" runat="server" DataTextField="Namee" viewstate="enabled"
DataValueField="ID" AutoPostBack="true" Height="213px" Width="152px"
ViewStateMode="Enabled" />
</div>
</div>
</form>
</body>
</html>
and the code for filling in data is :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsNothing(CType(Session("Login"), TikoClasses.Login)) Then
Response.Redirect("~/default.aspx")
ElseIf (CType(Session("Login"), TikoClasses.Login)).Admin = False Then
Response.Redirect("~/Loggedin/Welcome.aspx")
End If
ExamsList_ListBox.DataSource = DataModule.Exams_listall((CType(Session("Login"), TikoClasses.Login)).Inst_ID)
ExamsList_ListBox.DataBind()
End Sub
and selection changed even is:
Try
Dim k As Integer = ExamsList_ListBox.SelectedIndex
Dim tt As List(Of Integer) = ExamsList_ListBox.GetSelectedIndices.ToList
Dim t As Object = ExamsList_ListBox.SelectedValue
If ExamsList_ListBox.SelectedIndex > -1 Then
DataModule.GetExam(CType(Session("Login"), TikoClasses.Login).Inst_ID, ExamsList_ListBox.SelectedValue)
End If
Catch ex As Exception
End Try
Looking for help. Thanks in advance.
You need to put your bind code under !IsPostBack
if(!IsPostBack)
ExamsList_ListBox.DataSource = DataModule.Exams_listall((CType(Session("Login"), TikoClasses.Login)).Inst_ID)
ExamsList_ListBox.DataBind()
Endif
Since whenever your selection is Changed, your page_load event fired first and your selection is lost.