Calling Javascript on a loaded site [closed] - c#

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How would I call a function in Javascript on a loaded site in a Windows Form Application web browser? For those that have used Chrome, I'm looking to call Javascript like you can with the Javascript console.

Here is the answer:
WebBrowser wb = new WebBrowser;
wb.Navigate( ... link or Uri ...)
object[] args = new object[1];
args[0] = 12';
wb.Document.InvokeScript("functionName", args);
InvokeScript runs javascript functions. if you have a javascript function like function check(value){...} than your functionName is "check" and your args array hold value, if you have more parameters you can fill your args as much as parameters you want. The code above runs the javascript function as functionName(12);
If you want to access any element you can use this code:
wb.Document.GetElementById("ControlId")
.InnerText = "Bla bla"
.InvokeMember("click")

Related

System.Web.HttpUtility.HtmlDecode not working for test %3cstrong%3ebold %3c/strong%3etest [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
System.Web.HttpUtility.HtmlDecode not working for test %3cstrong%3ebold %3c/strong%3etest
Output should be <strong>bold </strong>test
I believe you want HttpUtility.UrlDecode in this case.
HtmlDecode is for things like <strong>
You are mixing up html encoding with url encoding. So it is normal that this does not work. Try using HttpUtility.UrlDecode()
Example for Url encoding:
%3cstrong%3ebold%3c/strong%3e
Example for HTML encoding:
<strong>bold</strong>
HttpUtility.HtmlDecode is used for converting HTML entities, e.g.
var sample = "<strong>bold </strong>test";
var result = HttpUtility.HtmlDecode(sample);
// result = "<strong>bold </strong>test"
You're looking for HttpUtility.UrlDecode, I believe, which surrenders:
var sample = "test %3cstrong%3ebold %3c/strong%3etest";
var result = HttpUtility.UrlDecode(sample);
// result = "<strong>bold </strong>test"

How to add a wiki page through ItemAdded event receiver coding on the addition of a new item in a list? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a list named 'List1' in which I have 'title ' and 'WikiLink' columns. I want to add a wiki page on the addition of a new item using ItemAdded event receiver code and update the link on 'WikiLink' column. Please help me out in this. I have been stuck on this for quite a while.
Thanks.
To create wiki page, you will have to add new item into one of the libraries that accepts wiki pages. Typically it's Site Pages, with code more less like this:
var l = (SPDocumentLibrary) SPContext.Current.Web.Lists["Site Pages"];
var folder = l.RootFolder;
var f = folder.Files.Add(string.Format("{0}/{1}", folder.ServerRelativeUrl.TrimEnd("/"), "MyWiki.aspx"), SPTemplateFileType.StandardPage);
//Site Absolute url + Site-relative Url, more info on MSDN.
var url = string.Format("{0}/{1}", SPContext.Current.Site.Url.TrimEnd("/"), f.Url);

Environment.CurrentDirectory in Resources [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm trying to put this string in my resources:
Environment.CurrentDirectory + \\Server Files\\
But whenever I load the string, the Environment.CurrentDirectory part is shown as normal text instead of the current directory path :(.
Example:
Console.WriteLine(Resources.ServerFilesLocation); // Doesn't give me a path, but just plain text.
Any runtime environment value cannot be stored as a string in resources. What you should do is create a layer between. Something like:
static class ResourceManager
{
public static string ServerFilesLocation {
get {
return String.Format(Resources.ServerFilesDirectory, Environment.CurrentDirectory);
// ServerFilesDirectory = "{0}\\Server Files\\" or something similar
}
}
}
And use it like: Console.WriteLine(ResourceManager.ServerFilesLocation);

How to deal with errors in function nesting and calling functions within other functions [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Scenario:
I have to check for user input (a string) that shouldn't contain <.%?/ symbols and if it does I remove them. I have 20 different places where I've to check it, actually, 20 different pages with each 20 different controls.
So I wrote a function like the following shortened example:
public string MyFunction (string userinput)
{
return userinput.replace("<"," ");
}
Now if I want to call this function from within another function and there's an error in this function's try catch block I want it to write an error to a Label on the main page, without interrupting the second function.
Also i am thinking of implementing conditional statement function calls too.
Usually it's best to let the calling function catch your error and to act upon it. Something like this (assuming C#, but your question wasn't clear about that and didn't have a working example):
try {
string resplacedString = yourReplaceFunction(userInput);
} catch (MyException e) {
Label1.Text = "An error occurred." + e.Description;
}

From Flash to Asp.net [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a flash file, but I haven't got the source codes.
How can I get values from it?
For example if it was a html form, I can get the posted values like below:
Request.Form("myValue")
But it doesn't work. How can I get the posted values?
Thanks.
In HTML, this code:
Request.Form("myValue")
Is not accessing the HTML source code; it's accessing the data sent in an HTTP form post. In HTML, the input names happen to dictate which form variables are sent.
ActionScript (the Flash programming language) can do a post just like HTML. Here's some sample code:
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("yourpage.aspx");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.myValue = "foo";
loader.addEventListener(Event.COMPLETE, handleCompletion);
loader.load(request);
private function handleCompletion(e : Event):void {
// Do things after the post completes
}
If you post to an ASP.NET page or handler using this code, Request.Form("myValue") would work the same way as if an HTML form had been posted.

Categories