1

I have made a ASP.net (aspx) website but need help to populate the textbox using the URL so I can send the URL to someone else and when they click/open the link the textbox is already filled out.

<asp:TextBox ID="txtMessages" runat="server" Width="300px"></asp:TextBox>

        string strMessage = txtMessages.Text;

Something like this -

http://localhost/TextInput.aspx?txtMessages=HelloWorld

So when the link is pressed the txtMessages textbox already has HelloWorld inserted into it.

I think the URL format would be something like that but it doesn't work.

1

2 Answers 2

1

Do you mean you want to read the URL and then populate the Text box with whatever is in the URL?

If so try:

String Txtmessage = Request.QueryString["txtMessages"];

Then use Txtmessage to populate your textbox

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for all the answers but your 1 line worked fine. however it is square brackets not normal ones.
Oh my bad, I've been working with vb.net a lot recently - That explains the normal brackets.. I'll update the answer.
1

Create a hyperlink on the page with your textbox:

HyperLink hl = new HyperLink();
hl.NavigateUrl = "yoursite.aspx?txtMessages=" + yourtextbox.Text;

on the page yoursite.aspx get the value on Page_Load:

 string txtMessage = Page.Request.QueryString.ToString();
 txtMessage = txtMessage.Replace("txtMessages=", "");

You can combine more QueryString like:

 "yoursite.aspx?action=change&txtMessages=" + yourtextbox.Text;

and grab it like:

string action = Page.Request.QueryString["action"].ToString();
string txtMessage = Page.Request.QueryString["txtMessages"].ToString();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.