I have response form in asp.net. I want on send button click the button text should change from send to please wait & once it is send it should back to it's default value text 'send'. can any one help?
code
Protected Sub submit_client_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submit_client.Click
Try
Dim pattern As String
pattern = "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*#([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"
If Regex.IsMatch(TextBox3.Text, pattern) Then
Label2.Text = ""
Else
Label2.Text = "Not a valid Email address "
End If
Dim emails As New List(Of String)()
generate.Visible = True
clear.Visible = True
SendHTMLMail()
'For Each item As ListViewItem In lvCustomers.Items
' Dim ck As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
' If ck.Checked Then
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
try like this:
MyButton.Text="Sending"
SendHTMLMail()
Thread.Sleep(3000) // add this & remove SendHTMLMail() for testing
MyButton.Text="Send"
Related
I have a page on the website that display a client details in text boxes.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not page.IsPostBack Then
Dim dh As New Datahandler
Dim CI As ClientInfomation = dh.GETClientInfomationWithClientID(Session("ClientID"))
txtClientID.Text = Session("ClientID")
txtCompany.Text = CI.Company
txtEmail.Text = CI.Email
txtPassword.text = CI.Password
dtSubcriptionEndDate.Text = CI.SubscriptionEndDate
txtContactName.Text = CI.ContactName
txtTelephoneNum.Text = CI.Telephone.ToString()
End If
The above code works,the code gets the client data from the database in the GETClientInfomationWithClientID(Session("ClientID")) and loads the data into a class, and from the class I load the data into the text boxes.
Here is where my problem starts. A user will now change his details in the text boxes and click the 'Save changes' button invoking the butSaveChanges_Click Event.
Protected Sub butSaveChanges_Click(sender As Object, e As EventArgs) Handles butSaveChanges.Click
Dim dh As New Datahandler
Dim CI As New ClientInfomation With {.ClientID = txtClientID.Text,
.Company = txtCompany.Text,
.ContactName = txtContactName.Text,
.Email = txtEmail.Text,
.Password = txtPassword.Text,
.SubscriptionEndDate = dtSubcriptionEndDate.Text,
.Telephone = txtTelephoneNum.Text}
If dh.SaveUserProfileChanegs(CI) = True Then
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('Changes has been saved')", True)
Else
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('Changes could not be saved')", True)
End If
End Sub
I just wanted to load the changed text values into the class, and load the class in the SaveUserProfileChanegs(CI) function that updates the new values in the database.
When the butSaveChanges_Click event is invoked I get a "(1) : error BC32022: 'Public Event Click As EventHandler' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event."
I have a DropDownList iniwhich on page load it loads up all the data into it, however when the user wants to make a change to what text is displayed they just simply click on the dropdown and select the new one. My question is How do I make it so it saves the new text value that they choose? Here is what I have now:
Private Sub cboCure_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCure.SelectedIndexChanged
cboCure.AutoPostBack = True
Dim objXMLDoc As New System.Xml.XmlDocument
Dim objNodeList As System.Xml.XmlNodeList
Dim strXML As String = ""
Dim url As String = ""
MaterialStuff = New Message.Material
Dim code As String = cboCure.SelectedItem.Text
cboCure.Items.Clear()
If cboCure.Items.Count < 1 Then
strXML = Message.GetCureCodes
objXMLDoc.LoadXml(strXML)
objNodeList = objXMLDoc.GetElementsByTagName("Material_Cure")
cboCure.Items.Add("")
For Each childNode As System.Xml.XmlNode In objNodeList.Item(0).ChildNodes
cboCure.Items.Add(New System.Web.UI.WebControls.ListItem(childNode.SelectSingleNode("CureCodeLetter").InnerText,
childNode.SelectSingleNode("CureCode").InnerText))
Next
End If
cboCure.SelectedItem.Text = code
End Sub
I want the variable code to be the new text value that the user clicks but I can't seem to get it right, it keeps showing up as "" or the value that is originally displayed when the page loads.
EDIT:
Here is my Page_Load
If Not Page.IsPostBack Then
...code
else
cboCure_SelectedIndexChanged(sender, e )
end if
I have a button which is not created dynamically. When I click on that button the number of lines in a textbox are counted. I store that in the variable called count. Depending on value of count I create buttons in panel.
Up to now it is working properly.
Now the click event of those buttons is not firing.
I have tried to google my question. But everywhere I got the same answer. Create the controls in Page_Init event. But how is it possible? I am getting the value of count from a textfile's lines, and that value of count decides how many button will be created in the panel.
Dim btnAllow As New Button
btnAllow.Text = "Allow"
btnAllow.ID = "btA" & x
AddHandler btnAllow.Click, AddressOf btnAllow_Click
btnAllowList.Add(btnAllow)
tdAllow.Controls.Add(btnAllow)
The code for btnAllow_Click
Protected Sub btnAllow_Click(ByVal sender As Object, ByVal e As System.EventArgs)
For x As Integer = 0 To btnAllowList.Count - 1
If sender.ID.SubString(3) = btnAllowList(x).ID.Substring(3) Then
Dim lineCount = IO.File.ReadAllLines(PendingRequestsPath).Length
Dim reader As New System.IO.StreamReader(DocumentViewersPath)
Dim allLines As New List(Of String)
Do While Not reader.EndOfStream
allLines.Add(reader.ReadLine())
Loop
reader.Close()
Dim DocumentViewerAlreadyExists As Boolean = False
For i As Integer = 0 To lineCount - 1
If ReadLine(i, allLines) = lblRequestorsList(x).Text Then
DocumentViewerAlreadyExists = True
Exit For
End If
Next
If DocumentViewerAlreadyExists = False Then
Dim Writer As System.IO.StreamWriter = IO.File.AppendText(DocumentViewersPath)
Writer.WriteLine(lblRequestorsList(x).Text)
End If
Dim line As String = ""
Dim r As IO.StreamReader = IO.File.OpenText(PendingRequestsPath)
Dim strFile As New ArrayList
While r.Peek <> -1 ' Loop through the file
line = r.ReadLine 'Read the next available line
' Check to see if the line contains what you're looking for.
' If not, add it to an ArrayList
If Not line.Contains(lblRequestorsList(x).Text) Then
strFile.Add(line)
End If
r.Close()
' Because we want to replace the content of the file, we first
' need to delete it.
If IO.File.Exists(PendingRequestsPath) Then
IO.File.Delete(PendingRequestsPath)
End If
' Create a StreamWriter object with the same filename
Dim objWriter As New IO.StreamWriter(PendingRequestsPath, True)
' Iterate through the ArrayList
For Each item As ArrayList In strFile
objWriter.WriteLine(item) ' Write the current item in the ArrayList to the file.
Next
objWriter.Flush()
objWriter.Close()
End While
End If
Next
End Sub
This worked for me:
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim NumberOfControls As Integer = 10
Session("CreateControls") = NumberOfControls
End Sub
Protected Sub btnAllow_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'This will be executed when clicking on the newly created buttons.
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Session("CreateControls") IsNot Nothing Then
For x As Integer = 0 To Convert.ToInt32(Session("CreateControls"))
Dim btnAllow As New Button
btnAllow.Text = "Allow"
btnAllow.ID = "btA" & x
AddHandler btnAllow.Click, AddressOf btnAllow_Click
Panel1.Controls.Add(btnAllow)
Next
End If
End Sub
In my user control, I have a text boxes that I used to create a new membership user. Each listbox has a datasource set to membership.getallusers() to fill the listbox. When the listbox index is changed, it populates the text boxes to allow editing. What I want to accomplish is: have each user listbox refresh to show the new user that gets created. Even though I call databind() after successfully creating the user, it doesn't update. On the form load I check if listbox.items.count < 1, then call databind(), which does work correctly. Any ideas?
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If ListBox3.Items.Count < 1 Then
For Each item As MembershipUser In Membership.GetAllUsers(0, Membership.GetAllUsers.Count + 1, Membership.GetAllUsers.Count)
ListBox3.Items.Add(item.UserName)
Next
Label1.Text = ListBox3.Items.Count
username = ListBox3.Items(0).ToString
Else
ListBox1.DataBind()
ListBox3.DataBind()
End If
user = Membership.GetUser
ListBox1.DataSource = Membership.GetAllUsers
ListBox1.DataBind()
ListBox2.DataSource = Roles.GetAllRoles
ListBox2.DataBind()
' ListBox3.DataSource = Membership.GetAllUsers
'ListBox3.DataBind()
End Sub
Protected Sub ListBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox3.SelectedIndexChanged
txtUsername.Text = user.UserName
txtEmail.Text = user.Email
txtQuestion.Text = user.PasswordQuestion
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try'Creates a new user
Dim status As System.Web.Security.MembershipCreateStatus
Membership.CreateUser(txtUsername.Text, txtPassword.Text, txtEmail.Text, txtQuestion.Text, txtAnswer.Text, True, status)
Label1.Text = "User " & txtUsername.Text & " was created"
'ListBox3.Items.Clear()
ListBox1.DataBind()
'ListBox3.DataBind()
Catch ex As Exception
Label1.Text = "Error:" & ex.Message
End Try
End Sub
You need to set the datasource again before you do the databind, like so:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try'Creates a new user
Dim status As System.Web.Security.MembershipCreateStatus
Membership.CreateUser(txtUsername.Text, txtPassword.Text, txtEmail.Text, txtQuestion.Text, txtAnswer.Text, True, status)
Label1.Text = "User " & txtUsername.Text & " was created"
'ListBox3.Items.Clear()
ListBox1.DataSource = Membership.GetAllUsers() ' Necessary because the DB has changed
ListBox1.DataBind()
'ListBox3.DataBind()
Catch ex As Exception
Label1.Text = "Error:" & ex.Message
End Try
End Sub
When you call databind, you might think that that's the moment the Listbox will call the method you gave it as a datasource, but that's not the case. The moment you assign the datasource, the data is retrieved. When you actually call the Databind-method, the Listbox will create the necessary internal controls
How to use Java script alert msg in code behind? This message will be display after save the data.
Here is my code,
enter code here
Protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Add.Click
'add new class
Dim DbClassMst = New ClassMst()
Dim dsClass As DataSet
Dim status As Integer = 0
Dim ResourceObject As Object
' 画面リソース定義
If SessionCtl.GetSession("RES_LANG").ToString = ResourceBase.LOCALE_JA Then
ResourceObject = New ResourceJa(SessionCtl.GetSession("RES_LANG"))
Else
ResourceObject = New ResourceEn(SessionCtl.GetSession("RES_LANG"))
End If
If NewClass.Text = "" Then
lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_REG)
Exit Sub
Else
'check to allow unique class
dsClass = DbClassMst.DisplayClass1(NewClass.Text)
If Trim(dsClass.Tables(0).Rows.Count > 0) Then
status = 1
End If
If dsClass.Tables(0).Rows.Count < 10 Then
If status = 0 Then
'insert class
DbClassMst.InsertClassNew(NewClass.Text, dsClass.Tables(0).Rows.Count + 1)
PopulateClassName()
NewClass.Text = ""
Dim AlertMsg As String = ""
AlertMsg = "<script language='javascript'>alert('Data has been saved');</script>"
*********Here I need alert msg.
Else
lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_EXIST)
Exit Sub
End If
Else
lblErrMsg.Text = ResourceObject.getMsg(ResourceBase.NEW_CLASS_MAX)
End If
End If
End Sub
but is not working. give me an idea.
A better way to do this is to have this as a utility method in a common class:
Friend Module MyUtilities
Public Sub Alert(ByVal page As Page, ByVal message As String)
Dim alertMessage As String = "alert('" & message & "');"
page.ClientScript.RegisterStartupScript(page.[GetType](), "showAlert", alertMessage, True)
End Sub
End Module
This can be used in a page like this:
MyUtilities.Alert(Me, "Sample alert!!!!!")
Your code looks so simpler. Hope this helps!
You should register this script to your page, so this script will be sent to the client.
Page.ClientScript.RegisterStartupScript(typeof(YourPage),
"myScripts",
"<script language='javascript'>alert('Data has been saved');</script>");
Dim someScript As String = ""
someScript = "alert('Your Leave request has been registered');"
Page.ClientScript.RegisterStartupScript(Me.GetType(), "onload", someScript)