将不同的局部变量传递给点击事件
pass different local variable to click event
我想将内部 ID 值传递给 btn_click 事件。在这里,我在 运行 RunStoreProcedure 中的一些代码之后动态获取 ID 值。从 RunStoreProcedure 获取 ID 值后如何全局声明?
public void RunStoreProcedure()
{
string ID = "123456";//
}
protected void btn_Click(object sender, EventArgs e)
{
Response.AddHeader("content-disposition", "attachment;filename="+ ID +".doc");
}
在函数外声明string ID = "";
为全局变量。
你的 RunStoreProcedure
应该是这样的:
public void RunStoreProcedure()
{
//your logic here.
ID = result.ToString();
}
因此,您的 ID
变量的值将来自存储过程或您想要的任何方式,现在可以在 btn_Click
事件中传递。
希望这能理清思路。
如果您想从包括不同 ID 在内的不同函数传递它,请执行此操作。
public static string id="";
public void RunStoreProcedure()
{
string ID = "123456";
id=ID;
}
protected void btn_Click(object sender, EventArgs e)
{
Response.AddHeader("content-disposition", "attachment;filename="+ id +".doc");
}
我想将内部 ID 值传递给 btn_click 事件。在这里,我在 运行 RunStoreProcedure 中的一些代码之后动态获取 ID 值。从 RunStoreProcedure 获取 ID 值后如何全局声明?
public void RunStoreProcedure()
{
string ID = "123456";//
}
protected void btn_Click(object sender, EventArgs e)
{
Response.AddHeader("content-disposition", "attachment;filename="+ ID +".doc");
}
在函数外声明string ID = "";
为全局变量。
你的 RunStoreProcedure
应该是这样的:
public void RunStoreProcedure()
{
//your logic here.
ID = result.ToString();
}
因此,您的 ID
变量的值将来自存储过程或您想要的任何方式,现在可以在 btn_Click
事件中传递。
希望这能理清思路。
如果您想从包括不同 ID 在内的不同函数传递它,请执行此操作。
public static string id="";
public void RunStoreProcedure()
{
string ID = "123456";
id=ID;
}
protected void btn_Click(object sender, EventArgs e)
{
Response.AddHeader("content-disposition", "attachment;filename="+ id +".doc");
}