i have create a user control search.ascx with query string values and i m accessing this page from Parent page(Rcomm.aspx) and now this Page is open from another page(view.apsx) on button click using hyperlink navigateurl. my question is that how can i pass my user control query string from view.aspx
A user control has access to the page's URL the same as any normal ASP.NET page does; thus, in order to retrieve the QueryString from the user control, the normal syntax will work:
Request.QueryString('key')
However, I consider this poor style, because I think of user controls as a modular item you can embed in ANY page: thus tying it directly to a particular querystring value seems to go against that. However you may have valid reasons for this.
I'm not sure I understand the second part of your question:
how i make hyperlink navigate URL with query string for open my Rcomm.aspx
Could you please clarify?
ADDITIONAL: OK it seems to me like you have a link in your user control, and want to use a querystring value from the user control's parent page (Rcomm.aspx) to use in the link to a third page. Correct me if I am wrong.
In this case, you would read the querystring from the user control, then append to another URL using NavigateURL:
URL: Rcomm.aspx?field=value
(in code behind:)
Dim qs as string
qs = Request.QueryString('field')
MyHyperlink.NavigateURL = "newpage.aspx?field2=" & qs
Or something similar. Yes?
Related
I have a page called webForm1, this page contains a textfield, when a user enters a value, I want the value to show up in a label on webForm2, when I do that, I am getting an error:
Label1 is inaccessible due to its protection level
This is what I am doing in webForm1
webForm2 webform = new webForm2();
webform.Label = textBox1.Text;
Response.redirect("~/webForm2.aspx");
but the above is not working, I am new to programming and not familiar with classes and complicated programming, what is the easiest way to get the value of the textbox in the label?
Thank you.
You can't instantiate the page class (webForm2) in your current page. You'll have to pass the value in another way to the second page and then bind the label. As Jason P says, the ASP.NET framework instantiates the webForm2 page for you, you can't do it yourself.
If the data is not sensitive, use the Query String:
Response.Redirect("~/webForm2.aspx?label=" + textBox1.Text);
This will redirect the user to a page with the url of whatever.com/webForm2.aspx?label=whatevervalue. On the second page, you can pull the text from the query string and bind it to the label:
public void Page_Load(object sender, EventArgs e)
{
Label.Text = Request.QueryString["label"].ToString();
}
Unlike WinForms, you don't instantiate the next form like that. Essentially, your first two lines are incorrect for WebForms. The third line is where you want to focus your attention. You redirect the user to the second form, allowing the framework to take care of instantiating it.
This is because WebForms, despite being "forms", is still an HTTP web application and does everything through requests and responses. By issuing a redirect you are telling the client to abandon the current page and make a new request for the specified page.
There are a number of ways to send a value to this next page. You can store it in some persisted medium (such as a database), you can use session state, etc. Probably the simplest approach at the moment would be to include it on the query string:
Response.Redirect("~/webForm2.aspx?label=" + textBox1.Text);
Then in the next page you'd get the string from:
Request.QueryString["label"]
You may want to URL-encode the text value first, I don't know if Redirect() does that for you. Also keep in mind that this isn't a "secure" transfer of data from one page to the next, because the client has full access to modify values in the URL. So if this is in any way sensitive data then you'll want to look into other approaches. (Keep in mind that "sensitive" could be a relative term... The information itself might not be sensitive but you might be doing system-sensitive things with it on the next page, which we can't know from the code posted.)
I need help with connecting to a certain website via my username & password.
With WebClient I can fill the username field and the password field, but how do I invoke the click method of the button?
And How can I fill a specific textBox that doesn't have an ID?
I tried doing this with webBrowser, but every time I navigate I have to use a new function every time, which makes the work much harder.
Thanks.
What you're trying to do is wrong. If you want to Post some data to a web address (a URL), simply create a web form (a simple HTML form), fill it, and then send it. Just consider these notes:
Your HTML's form action should be the exact URL of the form you're imitating.
Your input controls should have the same name attribute value.
For more information, see Form Spoofing
Look at the web browser control and see if you can use that inside your windows form to perform the task that you are doing. Once you are satisfied with the results, you can make the web browser control invisible, and it'll work just like you do with web response and request calls.
View the source code and find the id of the button (say "Login").
Then use:
HtmlElement elem = webBrowser1.Document.GetElementById("Login");
if (elem != null)
elem.InvokeMember("click");
I have a webpage 'WPwp1.aspx' and another webpage 'FLcourt.aspx'
In WPwp1.aspx i have DropDownList2,DropDownList3,TextBox1,TextBox2,TextBox3 and a LinkButton1
On click of a link button i want to
redirect to FLcourt.aspx.
FLcourt.aspx also has the controls
that are there in
WPwp1.aspx(DropDownList2,DropDownList3,TextBox1,TextBox2,TextBox3)
When user input value in the controls present in WPwp1.aspx and clicks on LinkButton1, the user should be able to see all the values that were being given as input in 'WPwp1.aspx' into the asp.net controls in 'FLcourt.aspx'.
How is it possible to pass values being input in some controls in a webpage to similar controls in another webpage?
Yes, you have several options:
Use Session variables. This is the less scalable way. Just before Response.Redirect, store
your values in Session and get them in the Page_Load of the target page.
Using QueryString. Pass the values in a query string:
Response.Redirect(
string.Format("FLcourt.aspx?value1={0}&value2={1}",
HttpUtility.UrlEncode(value1),
HttpUtility.UrlEncode(value2)));
And in the second page:
var value1 = Request.QueryString["value1"];
UPDATE
Using cookies (the client's browser must have them enabled). Set cookies before Redirect:
Response.Cookies["MyValues"]["Value1"] = value1;
In the target page:
if(Request.Cookies["MyValues"] != null)
{
var value1 = Request.Cookies["MyValues"]["Value1"];
//...
}
(but you have to check that Request.Cookies["MyValues"] is not null before)
You can try this out.
In your source page ("WPwp1.aspx") create properties for each control i.e. DropDownList2,DropDownList3,TextBox1,TextBox2,TextBox3.
Give "PostBackUrl" property of the linkbutton to the page you want to redirect, in your case it will be "FLcourt.aspx".
In the destination page ("FLcourt.aspx") access the previous page with the help of "PreviousPage" class. This class will give you the properties which you have written in point1.
Hope this helps!
Regards,
Samar
See: http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
To summarize and answer your question directly, you can:
Use a query string.
Get HTTP POST information from the source page.
And since both pages appear to be in the same Web Application, you can also:
Use session state.
Create public properties in the source page and access the property values in the target page.
Get control information in the target page from controls in the source page using the PreviousPage object. This option has a particular performance disadvantage as a call to PreviousPage results in the instantiation of the object and the processing of its life-cycle up to, but not including PreRender.
Sometimes, though, it is simpler to avoid cross-page postbacks and simulate the multiple pages/stages with Panel or MultiView controls.
Use sessions
Use cookies
Use Applications (global)
Post Back URL
Query String
Server.Transfer
Static Variables (global)
http://www.herongyang.com/VBScript/IIS-ASP-Object-Example-Pass-Value-between-Pages.html
its shown how you do it between two pages.
I have a page that requires the user to go through several steps, however step is performed on the same ASPX page with different panels being displayed.
However this is a requirement that each step has a different URL, this could be a simple as a query string parameter, for example:
Step 1:
/member/signup.aspx?step=1
Step 2:
/member/signup.aspx?step=2
Step 3:
/member/signup.aspx?step=3
However I don't want to have to redirect the user to the new URL each time they continue to the next step, this would involve a lot of redirecting and also a switch statement on the page load to work out which step the user is on.
It would be better if I could alter the URL that is displayed to the user when the original request is sent back to the user, i.e. the user click "next" on step 1 the page then does some processing and then alters response so that the user then sees the step 2 URL but without any redirection.
Any ideas would be greatly appreciated.
Could you convert your Panels into steps in a Wizard control?
It would be a little more complicated than you probably want, but you could achieve this effect with the PostBackUrl property of the submitting button. I'm assuming each panel has its own "submit" button, and they could all use this property to "advance" the process. The drawback is that in order to get to submitted controls, you'd need to use the Page.PreviousPage property in order to access any controls and their values.
You could programmatically alter the PostbackUrl property of your 'Next' button on each Page_Load, based on the query string value. This is a bit strange though, as you wouldn't be able to use a standard event handler for the button click, and you'd have to use the PreviousPage property of the Page to get the data from the previous tab.
I'd say challenge this requirement. Why would anyone need to jump into the middle step? If it's a case of displaying the progress to the user, do this on the page, not in the URL.
You require that each step has different URL, than Response.Redirect is the only option. As you want to avoid the redirection, you can use IFrame but IFrame URL is not visible to user on his browser. I think redirect option is ugly(for both SERVER and CLIENT) as in this case, you first post on the page and than get that page. The best solution is POST BACK with some varible tracking step.
You could implement a form or url rewriting so that your urls end up being
/member/signup/step1/
/member/signup/step2/
/member/signup/step3/
To do this use the
HttpContext.RewritePath method which means you can rewrite /member/signup/step1/ to /member/signup.aspx?step=1 for example. See an example here.
I would also use the PRG (post request get) pattern so that each next link posts the form data of that step to the session then redirects the user top the correct next url. this will ensure that the user can navigate back and forth through the steps safely and also the url will remain intact in all your posts.
Check out server.transfer
I am designing a winforms based testing app (which is based upon WatiN). I specify a page to test and the value to insert into a textbox, and then click the corresponding button.
Is it possible to add a query string to the request I make (when clicking button) and then get the URL of the next page? Based on this, I need to screen scrape it.
Not sure about Watin syntax, but in Watir (Ruby version) you can get URL of the page displayed in browser with
browser.url
Or do you need to get URL of the next page before you open it?
Based on your comment to AmitK, Ċ½eljko's answer is right.
In WatiN (and C#), the syntax is:
Console.WriteLine("The current page is:" + ie.Url.ToString());
(just in case: 'ie' is the browser reference, use whatever object you use to enter text and click buttons)
What exactly do you mean by "next page" ? Does the form when submitted redirect to another page? If so, you will receive a HTTP 302/303 status code with the URL of the next page.