How can I get the parameters from url
48,613
Solution 1
To get the value for the http get Parameter:
string testParameter = Request.QueryString["Text"];
then set the Textbox Text
Name.Text = testParameter
Also its strongly suggested to not take Content directly from the url as malicious content could be injected that way into your page. ASP offers some protection from this, still its considered a good practice.
Solution 2
If you want get text value from Querystring you need to use:
var text = (string)Request.QueryString["Text"];
Then you can bind it to Text property of TextBox Name:
Name.Text = text;
Update: You can initialize you server controls values only on PageLoad event.
Author by
bowang
Updated on August 21, 2020Comments
-
bowang over 3 years
I'm writing an aspx to let users check the filename and create a file with that name
the url is
/sites/usitp/_layouts/CreateWebPage.aspx?List=%7b74AB081E-59FB-45A5-876D- 284607DA03C6%7d&RootFolder=%3bText=%27SD_RMDS%27
how can I parse the parameter 'Text' and show in the textbox?
<div> <asp:TextBox id="Name" runat="server" /> </div>
the aspx text box is this, I tried
<asp:TextBox id="Name" runat="server" text=<%$Request.QueryString['Text']%>></asp:TextBox>>
but it didn't work
anyone can help me out?
-
bowang over 11 yearsbut I wanna write one single line inside the aspx <textbox> tag, any good idea?
-
bowang over 11 yearsthank you! but it didn't work, where can I call the function DataBind()? where can I put this code?
-
bowang over 11 yearsthe Name.Text is in the <TextBox> ?
-
Kevin Main over 11 yearsYour TextBox is in your filename.aspx page right? So you should have a code behind file called filename.aspx.cs - in there you by default get a Page_Load function (if not you will have to add this) - add the DataBind() call inside the PageLoad.
-
bowang over 11 yearshow about the Name.Text = Request.QueryString["Text"];? how can I use this?
-
Kevin Main over 11 yearsTo do it that way (the recommended way) - ignore everything else above and simply add that one line into the Page_Load method - build it and should now work.
-
bowang over 11 yearsthis sharepoint file .aspx is in the Layout folder, how can I find the cs file that controls this? can you help me'
-
Th 00 mÄ s over 11 yearsCould your clarify on "You can initialize you server controls values only on PageLoad event.". I guess i know what you mean but its properly not clear to the OP.
-
bowang over 11 yearsso I just put Name.Text = Request.QueryString["Text"]; in the function Page_Load(), that will work right?
-
Kevin Main over 11 yearsYes, it is that simple - it is pretty much ASP.NET 101 really. I would suggest you read a few tutorials, watch some videos and maybe get yourself a good book before going much further.
-
Kirill Bestemyanov over 11 yearsPage lifecycle contains next events: PreInit, Init, PreLoad, Load, Control (postback) events, LoadComplete, PreRender, SaveStateComplete, Render, Unload. All events are being catched for specific operations. PageLoad Event is a time when page is stable, it has been initialized and its state has been reconstructed. So it is time to setup values of controls from sources other than control postback events. msdn.microsoft.com/en-us/library/…
-
bowang over 11 yearsthat's coooooool! so what should I write in the <TextBox>?
-
Th 00 mÄ s over 11 yearsThanks for adding that information. Ofcourse methods started from the event "PageLoad" can change controls themself.
-
Shadow The Kid Wizard over 11 years@bowang nothing - that's the beauty in this.
-
bowang over 11 yearsoops, I just add the script under the buttom and a run time error happened, something wrong with the js file?(I just added them at the end and did nothing more, even not editing the tag)
-
bowang over 11 yearssharepoint doesn't allow me to see the .cs code behind it, is there any other way I can do?