How to get string from url in ASP.NET webforms?

纵饮孤独 提交于 2020-02-23 09:58:08

问题


I think my tittle is inaccurate.

When a user clicks on a button I need it to do this:

Response.Redirect("Login.aspx?userid=XX");

How can I get the "userid?" from ?userid. so I can show a page. Like doing "?page=3" and show page 3, in the same page or something.

The Button code is: (just if you need it)

protected void LoginButton_Click(object sender, EventArgs e)
{
    Response.Redirect("Login.aspx");
}

Thanks a lot! Sorry if I didn't ask it good, and sorry for the bad English.


回答1:


Use Request.QueryString:

First Page Sends them another page with their user id in the url:

Response.Redirect("AfterLogIn.aspx?userid=23");

You then Read it using the below code:

var g = Request.QueryString["userid"] //this value should be 23 now

You could then use this g variable to do any amount of custom things (Hide panels, show controls, etc.)




回答2:


You can do something like this

protected void LoginButton_Click(object sender, EventArgs e)
        {
                var id = // whatever userid
                Response.Redirect("Login.aspx?userid="+ id);
        }

and in the pageload of Login page

    var userid = Request.QueryString["userid"];

ASP.NET State Management will explain further.

Hope this helps



来源:https://stackoverflow.com/questions/7854187/how-to-get-string-from-url-in-asp-net-webforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!