简体   繁体   English

将值从一页传递到另一个使用按钮或链接和代码?

[英]Pass a value from one page to another use button or link and code?

In asp.net, C#, I actually want 3 conditions on a particular click to delete a record: 1. Ask for confirmation 2. Redirect to another page 3. Pass the id of the record to be deleted internally(not present in any text field or anything) to the next page whose record has to be deleted 在C#的asp.net中,我实际上希望对特定的单击操作有3个条件来删除记录:1.要求确认2.重定向到另一页3.传递要在内部删除的记录的ID(不以任何文本形式出现字段或其他内容)到下一个必须删除其记录的页面

If i use a link i an fulfill the 2nd and 3rd condition by using a query string 如果我使用链接,则可以通过使用查询字符串满足第二个和第三个条件

but if i use a button, then i can fulfill the 1st and 2nd condition. 但是,如果我使用按钮,则可以满足第一条件和第二条件。

and in the onclick i redirect it to the next page. 并在onclick中将其重定向到下一页。

I tried with postback url also, it gives the value 0. 我也尝试使用回发网址,它的值为0。

Can anybody tell me what should i use and how so that all the 3 conditions are fulfilled? 谁能告诉我应该使用什么以及如何满足这三个条件?

Ok i got the answer to this. 好吧,我得到了答案。 i simple used this in the onclick event of the button: 我简单地在按钮的onclick事件中使用了它:

string redirect = string.Format("~/Admin-DeleteEmployee.aspx?Id=" + id + ""); 字符串重定向= string.Format(“〜/ Admin-DeleteEmployee.aspx?Id =” + id +“”); Response.Redirect(redirect); Response.Redirect(重定向);

and i can ask for confirmation also and redirect the page along with the value. 我也可以要求确认,并重定向页面和值。 So all the three conditions are satisfied. 因此,这三个条件都满足。 Thanx a lot! 非常感谢!

If the ID of the record is passed in the ID of the button, you can use something like this when it is clicked 如果记录的ID在按钮的ID中传递,则可以在单击该按钮时使用类似的内容

protected void ButtonCliked(object sender, EventArgs e)
{

    string buttonID = "";
    if (sender is Button)
    {
        buttonID = ((Button)sender).ClientID;

        string url = "RedirectUrl.aspx?buttonID=" + buttonID;
        Response.Redirect(url);
    }
}

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM