How to add scroll delay in this coding for marquee ?
It will not scroll till the last character, it will disappear when first character in literal1 will touch the left side ...
i want it will scroll till last ..character
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim example As String = TextBox1.Text
Dim str As String = "<img src=a.gif/>"
Dim resulte As String = "<MARQUEE>" & str & " " & example & "</MARQUEE>"
Literal1.Text = resulte
End Sub
You need to set the scrolldelay attribute to the MARQUEE tag. So an example of this would be:
Dim resulte As String = "<MARQUEE SCROLLDELAY=500>" & str & " " & example & "</MARQUEE>"
Related
I have a date in the format '13092017' to which i have to add separator '-'and display in the text box using vb.net.
Private Sub SettlementDetailUpload_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim s1 As String = "13092017"
Catch ex As Exception
End Try
End Sub
You can do it like that :
Private Sub SettlementDetailUpload_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim s1 As String = "13092017"
Dim DayStr, MonthStr, YearStr, FinalDate As String
DayStr = s1.Remove(2)
MonthStr = s1.Substring(2, 2) 'The first '2' is where to start cutting and the 2nd '2' is how much you need to cutm which is 2 in this case.
YearStr = s1.Substring(4)
FinalDate = DayStr & "-" & MonthStr & "-" & YearStr
Msgbox(FinalDate)
Catch : End Try
End Sub
Hope it will be useful :)
Other than Request.Form("example") which use the name of the textbox. I want to know if there is any other way to get the value rather than using the Request.Form. I hope you guys understand what I mean and I hope this is not a dumb question. As I'm having problem using the name to get the value of what the textbox consist.
So I thought of using the id to get the value do tell me if that could work.And I would also like to know how it works.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
For Each row As DataRow In cardDT.Rows
Literal1.Text += "<tr>"
Literal1.Text += "<td><input type='text' id='test" & i & "' name='test" & i & "' value='" & row("Date") & "' maxlength='20'></td>"
Literal1.Text += "<td><input id='Checkbox1' type='checkbox' name='chk" & i & "' /></td>"
Literal1.Text += "</tr>"
i += 1
Next
Literal1.Text += " </table>"
End Sub
This is the button, for now is just check the value stored in request.form but when I click on this button I receive an error when I used the name:
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Dim i = 0
For Each row As DataRow In EmployeeDt.Rows
Dim t = Request.Form("test" & i)
If Request.Form("check" & i) <> "" Then
MsgBox("check" & i & " " & t)
End If
i += 1
Next
End Sub
There are two ways. You can choose which one suits your needs:
Change your html input control to asp:TextBox control. This will still render in the browser as html input anyways. So it shouldn't make a difference, but you would be able to access it in your code-behind. You can then get its value by ControlId.Text.
Just add the RunAt="Server" attribute on your html input (textbox) control, and you can access it in the code-behind as any other server side control. You can then probably get it value by ControlId.Value.
I got a toolbar with different actions the user can start. In the user interface it looks like:
If I press on the "Ok" button the value will not known at the backend. My code structure is the following:
Configuration of an action
<Action Id="MyAction" Name="Action with Form">
<Form>
<asp:TextBox xmlns:asp="System.Web.UI.WebControls" ID="txtValue" runat="server" />
</Form>
</Action>
ASPX-File
<asp:Content ContentPlaceHolderID="cphToolbar" Runat="Server">
<asp:PlaceHolder ID="plhToolbar" runat="server" />
</asp:Content>
VB-File to the ASPX-File
Partial Class Form
Inherits UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.plhToolbar.Controls.Add(Me.CreateActionToolbar(<XML configuration element for the toolbar>))
End Sub
End Class
Page base class
Namespace UI
Public MustInherit Class Page
Inherits System.Web.UI.Page
Protected Overridable Function CreateActionToolbar(source As XmlElement) As Interfaces.IActions
Dim oAction As Interfaces.IActions = Me.LoadControl("~/Controls/Toolbar/Actions.ascx")
For Each element As XmlElement In source.SelectNodes("node()").OfType(Of XmlElement)()
Dim NewItem As New Controls.ActionItem
'set settings for the toolbar element
'add fields to form
For Each Item As XmlNode In element.SelectNodes("Form/node()", oNamespaceManager)
If (TypeOf Item Is XmlElement) Then
If (NewItem.Fields Is Nothing) Then NewItem.Fields = New List(Of XmlElement)
NewItem.Fields.Add(Item)
End If
Next
oAction.Items.Add(NewItem)
Next
Return oAction
End Function
End Class
End Namespace
Action user control
Partial Class Actions
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For Each Item As ActionItem In Me.Items
'set settings for action
If (Not (Item.Fields Is Nothing)) Then
Dim oPanel As New Panel
oPanel.ID = "dlgActionPanel" & Me.dlgAction.Controls.Count
Me.dlgAction.Controls.Add(oPanel)
Dim oFields As New Panel
oFields.ID = oPanel.ID & "_Controls"
For Each Field As XmlElement In Item.Fields
Dim oControl As System.Web.UI.Control = Nothing
Try
oControl = Me.ParseControl(Field.OuterXml)
Catch ex As Exception
oControl = New LiteralControl("<font style=""color:red;"">" & ex.Message & "</font>")
End Try
oFields.Controls.Add(oControl)
Next
Dim pnlResult As New Panel
Dim btnOk As New Button
btnOk.ID = "btnOk_" & oPanel.ID
AddHandler btnOk.Click, AddressOf Ok_Click
btnOk.Attributes.Add("onclick", "ShowWaitDialog();")
btnOk.Attributes.Add("ItemId", NewAnchor.Attributes("ItemId"))
btnOk.UseSubmitBehavior = False
btnOk.Text = Me.AcceptDialogText
pnlResult.Controls.Add(btnOk)
Dim btnCancel As New Button
btnCancel.Attributes.Add("onclick", "ShowWaitDialog();$('#" & oPanel.ClientID & "').dialog('close');CloseWaitDialog();return false;")
btnCancel.Text = Me.CancelDialogText
pnlResult.Controls.Add(btnCancel)
oPanel.Controls.Add(oFields)
oPanel.Controls.Add(pnlResult)
Dim strMessageControlId As String = oPanel.ClientID
strClientScript &= "$(""#" & strMessageControlId & """).dialog({" & NewLine
strClientScript &= " bgiframe:true, " & NewLine
strClientScript &= " autoOpen:false, " & NewLine
strClientScript &= " modal:true, " & NewLine
strClientScript &= " closeOnEscape:false, " & NewLine
strClientScript &= " width:600, " & NewLine
strClientScript &= " height:450, " & NewLine
strClientScript &= " minWidth:450, " & NewLine
strClientScript &= " minHeight:300, " & NewLine
If (Not (Item.Description Is Nothing)) Then strClientScript &= " title:'" & Item.Description & "', " & NewLine
strClientScript &= " open: function(event, ui) { $("".ui-dialog-titlebar-close"").hide(); } " & NewLine
strClientScript &= "});" & NewLine
If (String.IsNullOrEmpty(NewAnchor.Attributes("onclick"))) Then NewAnchor.Attributes.Add("onclick", String.Empty)
NewAnchor.Attributes("onclick") &= "$('#" & oPanel.ClientID & "').dialog('open');"
End If
Next
End Sub
Private Sub Ok_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim oDialog As Panel = Nothing
If (Not (String.IsNullOrEmpty(sender.ID))) Then oDialog = Me.dlgAction.FindControl(sender.ID.Substring(sender.ID.IndexOf("_") + 1) & "_Controls")
Dim oAction As ActionItem = Items.Find(Function(item) item.ItemId = sender.Attributes("ItemId"))
If (Not (oDialog Is Nothing)) Then
For Each Field As XmlElement In oAction.Fields
Dim oControl As WebControl = Nothing
If (Not (Field.SelectSingleNode("#Id|#ID") Is Nothing)) Then oControl = oDialog.FindControl(Field.SelectSingleNode("#Id|#ID").Value)
If (Not (oControl Is Nothing)) Then
Dim oParameter As SqlClient.SqlParameter = oAction.Parameters.Find(Function(item) item.ParameterName = "#" & oControl.ID.Substring(3))
If (Not (oParameter Is Nothing)) Then
Select Case oControl.GetType.ToString
Case GetType(TextBox).ToString
'After postback the value is empty!!!
If (Not (String.IsNullOrEmpty(CType(oControl, TextBox).Text))) Then oParameter.Value = CType(oControl, TextBox).Text
'more controls
Case Else
End Select
End If
End If
Next
End If
End Sub
End Class
Where is the fault that the value of the TextBox is after PostBack empty and not set because of the View State?
Thanks for any response.
I could solve it. The problem was that the jQuery dialog was not PostBack save. The solution was
$("#dialog").dialog({
appendTo:'form:first'
});
I am basically creating textboxes dynamically for adding a test to the database. The number of textboxes to be created was passed as a query string from the web page before. Here is the code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim NoOfQuestions As Integer = Request.QueryString("NoOfQuestions")
Dim txtboxQ(NoOfQuestions - 1) As TextBox
Dim txtboxA(NoOfQuestions - 1) As TextBox
For i = 1 To NoOfQuestions
Placeholder.Controls.Add(New LiteralControl("<span>Question " & i & "</span>"))
Placeholder.Controls.Add(txtboxQ(i - 1))
Placeholder.Controls.Add(New LiteralControl("</br>"))
Placeholder.Controls.Add(New LiteralControl("<span>Correct Answer</span>"))
Placeholder.Controls.Add(txtboxA(i - 1))
Placeholder.Controls.Add(New LiteralControl("</br>"))
Next
End Sub
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
'Some SQL stuff
Response.Redirect("HomePage.aspx")
End Sub
I am trying to pass both the textbox arrays that were declared in Page_Load to the other sub btnSubmit_Click. I tried to pass it as parameter like this but it didn't seem to work:
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs, ByRef txtboxQ() As TextBox, ByRef txtboxA As TextBox) Handles btnSubmit.Click
'Some SQL stuff
Response.Redirect("HomePage.aspx")
End Sub
Quiet lost here, thanks for your help!
You can pass the textboxes content as output parameters in the querystring, as you did with your input parameter NoOfQuestions
Dim sQuery As String
For i = 1 To NoOfQuestions
sQuery &= "Question" & i & " & txtboxQ(i - 1).Text & "Answer" & i & "=" & txtboxA(i - 1).Text
Next i
Response.Redirect("HomePage.aspx?" & sQuery)
And the parse the query string in the Page Load event of HomePage.aspx. You can also pass the values as session variables
Session("Question1") = txtboxQ(i - 1).Text
...
And then
Dim question1 As String = Session("Question1")
....
Declare a list of text boxes on page level
Public textQ = New List(Of TextBox)
Public textA = New List(Of TextBox)
Change your code to following
For i = 1 To NoOfQuestions
Placeholder.Controls.Add(New LiteralControl("<span>Question " & i & "</span>"))
Dim txtboxq = New TextBox()
txtboxq.ID = "txtq_" & i
Placeholder.Controls.Add(txtboxq)
textQ.Add(txtboxq)
Placeholder.Controls.Add(New LiteralControl("</br>"))
Placeholder.Controls.Add(New LiteralControl("<span>Correct Answer</span>"))
Dim txtboxa = New TextBox()
txtboxa.ID = "txta_" & i
Placeholder.Controls.Add(txtboxa)
textA.Add(txtboxa)
Placeholder.Controls.Add(txtboxa)
Placeholder.Controls.Add(New LiteralControl("</br>"))
Next
then access the values in the list for any purpose, may be print values on submit or whatever..
eg:
For Each tb As TextBox In Me.textQ
Me.label1.Text = Me.label1.Text & tb.Text.Trim()
Next
Wondering why would you want to pass the variables like that when you can declare the variables in page level and access it from any method/function. Any special requirement?
what you are trying to do here is unclear as well.
You can use global variable inside you class, and place it below your class code. And if you want to use it, you just call that global variable.
I am trying to run some code on Page_PreRender but only want it to run on hyperlinks within a certain DIV.
What the code does is change the colour of a hyperlink if the NavigateUrl = the URL of the page the user is on.
I have some code that works but it changes the colour of every link on the page that matches when I only want it to happen within a certain div.
The DIV ID i want the hyperlinks changed in is 'subNav'
CURRENT CODE
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim filePath As String = "/~" & System.Web.HttpContext.Current.Request.Path
Dim strControlType As String
For Each ctrl As Control In Me.Controls
For Each subctrl As Control In ctrl.Controls
strControlType = Convert.ToString(subctrl.[GetType]())
If strControlType = "System.Web.UI.WebControls.HyperLink" Then
If filePath = "/" & DirectCast(subctrl, HyperLink).NavigateUrl Then
'DirectCast(subctrl, HyperLink).CssClass = "active"
DirectCast(subctrl, HyperLink).Attributes.Add("style", "color:#993366")
'Label2.Text = "/" & DirectCast(subctrl, HyperLink).NavigateUrl
End If
End If
Next
Next
End Sub
CODE IM TRYING
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim filePath As String = "/~" & System.Web.HttpContext.Current.Request.Path
Dim strControlType As String
Dim subNavDiv As HtmlControl = CType(FindControl("subNav"), HtmlControl)
For Each ctrl As Control In subNavDiv.Controls
For Each subctrl As Control In ctrl.Controls
strControlType = Convert.ToString(subctrl.[GetType]())
If strControlType = "System.Web.UI.WebControls.HyperLink" Then
If filePath = "/" & DirectCast(subctrl, HyperLink).NavigateUrl Then
'DirectCast(subctrl, HyperLink).CssClass = "active"
DirectCast(subctrl, HyperLink).Attributes.Add("style", "color:#993366")
'Label2.Text = "/" & DirectCast(subctrl, HyperLink).NavigateUrl
End If
End If
Next
Next
End Sub
Not sure if this is the way to go about it or not, but it doesn't seem to be working.
Thanks for any help.
J.
You will need to add a runat="server" tag to the div and give it an ID. Once you do that, you can find the DIV like this:
EDIT: Use Panel instead of DIV, and add HyperLink controls to the Panel, like this:
<asp:Panel ID="pnlLinks" runat="server">
<asp:HyperLink ID="lnk1" runat="server" Text="Link 1" />
<asp:HyperLink ID="lnk2" runat="server" Text="Link 2" />
</asp:Panel>
Then in your code behind, do this:
For Each lnk As HyperLink In pnlLinks.Controls.OfType(Of HyperLink)()
lnk.NavigateUrl = "/somefolder/somepage.aspx"
Next
UPDATE
I added in some code when iterating through the links:
Response.Write(DirectCast(subctrl, HyperLink).NavigateUrl & "<br />")
But when I added runat="server" to the div the hyperlinks I within the div were no longer writen out.
UPDATE2
Got there with your help, the panel bit definitely worked, thanks.
Final Code:
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Dim filePath As String = "/~" & System.Web.HttpContext.Current.Request.Path
For Each lnk As HyperLink In subNav.Controls.OfType(Of HyperLink)()
If filePath = "/" & lnk.NavigateUrl Then
DirectCast(lnk, HyperLink).CssClass = "active"
End If
Next
End Sub