Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the parameters from url

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?

like image 647
bowang Avatar asked Aug 20 '12 12:08

bowang


2 Answers

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.

like image 89
Th 00 mÄ s Avatar answered Oct 26 '22 05:10

Th 00 mÄ s


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.

like image 36
Kirill Bestemyanov Avatar answered Oct 26 '22 03:10

Kirill Bestemyanov