Hi I have a code using vb.net. I need to get the text in the textbox as a parameter for calling javascript function which set the text in the label on the parent page. I replace the new line with <br/>. But it still show the <br/>on the label. Would someone tell me what to solve it. Thanks in advance.
The text in the textbox:
test [ \ ^ $ . | ? * + ( )'
new line
The text shows in the parent label:
test [ ^ $ . | ? * + ( )'<br/>new line
There is my code int vb.net
Dim script as string=""
Dim strText As String = txtNote.Text.Trim.Replace("'", "\'")
strText = strText.Replace(Environment.NewLine, "<br/>")
script = "window.parent.showNote('" & Server.HtmlEncode(strText) & "');"
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.[GetType](), "EditNote", script, True)
There is javascript:
function showNote(txt){
$('#lbl').html(txt);
}
I changed the code and work:
Dim script as string=""
Dim strText As String = txtNote.Text.Trim.Replace("'", "\'")
strText A=Server.HtmlEncode(strText)
strText = strText.Replace(Environment.NewLine, "<br/>")
script = "window.parent.showNote('" & strText & "');"
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.[GetType](), "EditNote", script, True)
Related
I am setting value of hiddenfield from code behind in vb.net
If(condition)
hdmodulename.Value =Dt_Module.DefaultView(0).Item("vModuleCode").ToString() +
"-" + Dt_Module.DefaultView(0).Item("vModuleName").ToString()
Else
hdmodulename.Value = hdmodulename.Value + "'\n'" + Dt_Module.DefaultView(0).Item("vModuleCode").ToString() + "-" + Dt_Module.DefaultView(0).Item("vModuleName").ToString()
End If
now alert in javascript
i code like below:
alert('You cannot select ' + document.getElementById('<%=hdmodulename.ClientID%>').value);
Output :
'\n' is printed inseted of new line
so what is the probem??
Thanks A ton in advance
As for web pages, break lines with <br> or <p></p> tags. You can also Use Environment.NewLine with VB.
For JS use \n' for the line break -
alert("some text\nmore text in a new line");
Please try with Environment.NewLine for VB.net
as below:
Dim value As String = "[First" + _
Environment.NewLine + _
"Second]"
will return
[First
Second]
Not a vb expert, but shouldn't it be "\n" instead of "'\n'"?
The one in the vb code have both double and single.
I've been using Autohotkey for a while to access some elements on a webpage, I can do so just fine using: wb.document.elements[x].forms[x].value and assigning this to a value. I apologize but my knowledge of Javascript is very limited.
Recently I looked at the code for the page and noticed the following:
<script type="text/javascript" defer="defer">
form = new ActiveForm('EditingServiceInformationforSOMEGUY','Editing Service Information for SOME GUY');
data = {};
data.header = ["addressid", "contactid", "address1", "address2", "city", "state", "zip"];
data.body = [["275101010", "254101010", "1001 Maudlin", "Apt. 1774", "Beverly Hills", "CA", "90210"]];
I have been unsuccessfully trying to access the data.body portion of this through AHK. If I type in the address bar while viewing the page:
javascript: alert(data.body[0])
I get a messagebox with the data.body values comma separated.
I can't seem to replicate this through Autohotkey. I've tried a lot of different syntax but I'm missing something here. I'd like to get a msgbox with the same values that I'm seeing in the Javascript Alert, and then further manipulate them from there.
I've tried many different combinations in my script to show data.body as the list of comma separated variables, but can't seem to get it to fire correctly.
My current AHK code is below, the line that attempts to assign tempvar is the one I can't get right.
Settitlematchmode, 2
WinGetTitle, Webstring, Title of the page
wb := IEGet(Webstring)
tempvar := wb.document(data.header[0])
msgbox % tempvar . "|" . Isobject(tempvar)
IEGet(Name:="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
: RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
For wb in ComObjCreate( "Shell.Application" ).Windows
If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
Return wb
}
#vasili111 was on the right track. Try this:
Settitlematchmode, 2
WinGetTitle, Webstring, Title of the page
wb := IEGet(Webstring)
IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
window := ComObj(9,ComObjQuery(wb,IID,IID),1)
tempvar := window.data.header.0
; or use
;tempvar := window.eval("data.header[0]")
msgbox % tempvar . "|" . Isobject(tempvar)
IEGet(Name:="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
: RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
For wb in ComObjCreate( "Shell.Application" ).Windows
If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
Return wb
}
I have this VB.NET code for a ASP.NET Gridview :
Protected Sub GridView3_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(1).Attributes("onmouseover") = "this.style.cursor='hand';this.style.textDecoration='underline';"
e.Row.Cells(1).Attributes("onmouseout") = "this.style.textDecoration='none';"
Dim Index As Integer = e.Row.RowIndex
e.Row.Cells(1).Attributes("OnClick") = "window.open('AreaQuery.aspx?AreaID=" + GridView3.DataKeys(e.Row.RowIndex).Value.ToString + "');"
End If
End Sub
The Line of code :
e.Row.Cells(1).Attributes("OnClick") = "window.open('AreaQuery.aspx?AreaID=" + GridView3.DataKeys(e.Row.RowIndex).Value.ToString + "');"
Opens up the new page ( with the passed values ) in a new window , I need this to be in the same window as the page it's come from ... How do I achieve this & How would it be implemented?
try to use this '_self'
<script type="text/javascript">
window.open ('YourNewPage.htm','_self',false)
</script>
http://www.w3schools.com/jsref/met_win_open.asp
Link:- http://galaxyresumes.com/pricing/mid-career/
in link on the left side just below the Resume writing there are "?". If you hover the mouse on it, shows text box. I want to fetch those text. Please help me out. Below is code I tried:
WebElement ele = driver.findElement(By.xpath("//div[#id='item_1']//*[#src='http://galaxyresumes.com/wp-content/themes/responsive/images/level_icon.1.png']"));
//WebElement ele = driver.findElement(By.xpath("//html//body//div[3]//div//div//div[3]//form//div//div[2]//div//div//div//div[4]//div//div[2]//div"));
//Thread.sleep(5000);
String s = ele.getAttribute("span");
String s1 = ele.getAttribute("data-original-title");
String s2 = ele.getAttribute("title");
String s3 = ele.getText();
String s4 = ele.getAttribute("text");
System.out.println(s +"kuki1" + s1 + s2 + "kuki2" + s3 + "kuki3" + s4);
Actions act = new Actions(driver);
act.moveToElement(ele).build().perform();
act.pause(10000);
//Console.WriteLine(Element2ToolTip.text);
System.out.println(ele.getText() + ele.getAttribute("title")+ ele.getAttribute("data-original-title") + "kukii");
But result is "null".
Please help.
The link you've posted doesn't seem to have any "?". However assuming the hover text is shown in a stadard HTML way and not using jQuery or something, this javascript should get it back :
s2 = ele.getAttribute("title");
or if it's an image it might be
s2 = ele.getAttribute("alt");
But .. your code isn't javascript ! looks like Java to me. Wrong tag ?
I am doing a chat project in java.
Using my Server response through jquery-ajax , I am creating an html and append the html to div.
My jquery - html alert without empty string-name(note the id='user' in the alert) will be ,
after appending this in the chat area ,
After jquery-html alert with empty string-name(note the id='user' in the alert) will be ,
after appending this in the chat area ,
My jquery for creating the HTML will be ,
function send(name , message , time){
//name = $("#name").val();
//message = $("#message").val();
var user = "<div id='user' class='fontStyle'>"+name+"</div>";
var msg = "<div id='msg' class='fontStyle'>"+message+"</div>";
var timeStamp = "<div id='time' class='fontStyle'>"+time+"</div>";
var row = "<div id='msgSet' >"+ user + msg + timeStamp +"</div>";
alert(row);
return row;
}
There is no empty string will be present in chat area.
Hope our stack members will help me.
You can escape html your string so it keeps the white spaces. See details here.
Or you can trim your message string (=remove spaces at the beginning and end of it) with such an instruction, and then manualy add the spaces (with the code inside a div, span, ...):
s.replace(/\s+/g, ' ');