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.
if you please help me out i am trying to pass 3 different parameters in a page but i am new in asp.net C# and i don't know the correct syntax if you please help me out
;
For one parameter like this it works:
Response.Redirect("~/WebPage2.aspx?q=" + ListBox1.SelectedValue);
how can i write it for 3 parameters like this don't seem to work?
Response.Redirect("~/WebPage2.aspx?q=" + ListBox1.SelectedValue+"&cr="+ListBox3.SelectedValue+"&p="+ListBox1.SelectedValue)
thanks in advance
You forgot a + in your string concatenations after the cr parameter. This being said a far safer and better approach which ensures that your parameters are properly encoded is the following:
var parameters = HttpUtility.ParseQueryString(string.Empty);
parameters["q"] = ListBox1.SelectedValue;
parameters["cr"] = ListBox3.SelectedValue;
parameters["p"] = ListBox1.SelectedValue;
var url = string.Format("~/WebPage2.aspx?{0}", parameters.ToString());
Response.Redirect(url);
And of course if you are using ASP.NET MVC (as you've tagged your question with it) you would use:
return RedirectToAction("SomeAction", new {
q = ListBox1.SelectedValue,
cr = ListBox3.SelectedValue,
p = ListBox1.SelectedValue
});
I very sincerely hope that if you are using ASP.NET MVC then ListBox1 and ListBox2 is not what I think it is.
Here's what I typically do (assuming a constant number of parameters for each URL):
string url = "~/WebPage2.aspx?q={q}&cr={cr}&p={p}";
url = url.Replace("{q}", ListBox1.SelectedValue)
.Replace("{cr}", ListBox2.SelectedValue)
.Replace("{q}", ListBox3.SelectedValue);
Response.Redirect(url);
I have not tested it, but this may be relatively inefficient. The reason I do it this way is so I know exactly what the URL pattern looks like and which parameters are used.
It's a trade-off to be sure, and am curious to see other peoples' feedback.
Related
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"
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);
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 have php code that puts some values into an Array as follows:
$hunter=addslashes($MessageArray[1]);
$time=addslashes($MessageArray[2]);
I wrote the same code in C# and wanted to know if it was correct.
string Hunter = Messagearray[1].tostring();
string time = Messagearray[2].tostring();
As James mentioned, use Pascal casing:
string hunter = messageArray[1].ToString();
string time = messageArray[2].ToString();
Also, C# arrays are indexed starting at 0. You can change the starting index of arrays in PHP, but you can't in C#. Perhaps you do wish to take the 2nd and 3rd items, but keep it in mind. You might want:
string hunter = messageArray[0].ToString();
string time = messageArray[1].ToString();
As far as addslashes() goes, it will depend on your usage of hunter and time. If you're using them in a SQL statement, there are other ways of accomplishing the functionality of PHP's addslashes().
Snipped from Here
public static string AddSlashes(string input)
{
return System.Text.RegularExpressions.Regex.Replace(input, #"(\\)([\000\010\011\012\015\032\042\047\134\140])", "$2");
}
Usage:
//
var Messagearray = new object[] { "item 0", 1 };
var hunter = AddSlashes(Messagearray[0].ToString());
var time = AddSlashes(Messagearray[1].ToString());
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.
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 12 years ago.
I've written some code to generate a sequence of random characters, but it does not:
byte[] sbytes = { 1, 0, 1, 0, 1 };
String sstring;
System.Random r = new System.Random();
r.NextBytes(sbytes);
sstring = Convert.ToBase64String(sbytes);
sstring = Path.GetRandomFileName();
sstring = sstring.Replace("=", "");
sstring = sstring.Replace(".", "");
textBox1.Text = sstring.ToString();
I believe the problem is between NextBytes and ToBase64String. I don't know how to make this work. How do you do the correct conversion to pass it to a textbox for display?
If you want to generate a random password here's a great example. And here's another one which is more naive. Simply forget about the Path.GetRandomFileName function.
if you wrote
sstring += Path.GetRandomFileName();
I'm guessing the result would be more like what you are looking for however it's only pseudo random and you should take a look at the link Darin posted
You're replacing the random data with the filename:
sstring = Convert.ToBase64String(sbytes);
sstring = Path.GetRandomFileName();
The second statement ignores the existing value set by the first statement, so the calls to NextRandom() and ToBase64String are completely irrelevant.
What exactly are you trying to do?
EDIT: This isn't really a very good way of creating a random password. For one thing you should use SecureRandom rather than Random, and you might also want to avoid confusing features such as "0" and "O", and "l" and "1" looking the same. You could just use Path.GetRandomFileName on its own, but it's not really what it's designed for.