怎样在onclick事件中传值?(在线=)

guyking 2005-01-22 03:36:25
<a href="index_bblb_xx.aspx" onclick="Session['aaa'] = 'aaa';">aaaaa</a>

我是想在页面上点击连接后在session["aaa"]中放个值
...全文
568 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
guyking 2005-01-23
  • 打赏
  • 举报
回复
//*****************************************************************


string strSQL4 ="exec change_oncou '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_cou + "'";

objCommand=new SqlCommand(strSQL4,objConnection);

objConnection.Open ();
CheckBoxList1.DataSource = objCommand.ExecuteReader ();
CheckBoxList1.DataTextField ="cou_name";
CheckBoxList1.DataBind ();
objConnection.Close ();



}

private void Button2_Click(object sender, System.EventArgs e)
{
if(true)
{
string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec load_score_time '" + label_user.Text + "','" + label_isstu.Text + "'";
SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList1.DataSource = objCommand.ExecuteReader ();
DropDownList1.DataTextField ="score_time";
DropDownList1.DataBind ();
objConnection.Close ();

DropDownList1.Items.Insert(0,"全部");
DropDownList1.Items[0].Selected=true;

}

if(true)
{
if(label_isstu.Text=="学生")
{
//do nothing

}
else
{
string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec load_dep '" + label_user.Text + "','" + label_isstu.Text + "'";
SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList2.DataSource = objCommand.ExecuteReader ();
DropDownList2.DataTextField ="dep_name";
DropDownList2.DataBind ();
objConnection.Close ();

DropDownList2.Items.Insert(0,"全部");
DropDownList2.Items[0].Selected=true;

}


}

if(true)
{
if(label_isstu.Text=="学生")
{
//do nothing

}
else
{
string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec load_grade '" + label_user.Text + "','" + label_isstu.Text + "'";
SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList3.DataSource = objCommand.ExecuteReader ();
DropDownList3.DataTextField ="grade";
DropDownList3.DataBind ();
objConnection.Close ();

DropDownList3.Items.Insert(0,"全部");
DropDownList3.Items[0].Selected=true;

}


}

if(true)
{
if(label_isstu.Text=="学生")
{
//do nothing

}
else
{
string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec load_class '" + label_user.Text + "','" + label_isstu.Text + "'";
SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList4.DataSource = objCommand.ExecuteReader ();
DropDownList4.DataTextField ="class";
DropDownList4.DataBind ();
objConnection.Close ();

DropDownList4.Items.Insert(0,"全部");
DropDownList4.Items[0].Selected=true;

}


}

if(true)
{
string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec load_cou '" + label_user.Text + "','" + label_isstu.Text + "'";
SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
CheckBoxList1.DataSource = objCommand.ExecuteReader ();
CheckBoxList1.DataTextField ="cou_name";
CheckBoxList1.DataBind ();
objConnection.Close ();

}

if(true)
{
if(label_isstu.Text=="学生")
{
//do nothing

}
else
{
TextBox1.Text="";

}


}



}

private void CheckBoxList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//do nothing

}

private void Button3_Click(object sender, System.EventArgs e)
{
//全选


for(int i=0;i < CheckBoxList1.Items.Count;i++)
{
CheckBoxList1.Items[i].Selected=true;

}

}

private void Button4_Click(object sender, System.EventArgs e)
{
//全不选


for(int i=0;i < CheckBoxList1.Items.Count;i++)
{
CheckBoxList1.Items[i].Selected=false;

}

}








}
}
guyking 2005-01-23
  • 打赏
  • 举报
回复
//*****************************************************************


string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec change_onscore_time '" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_score_time + "'";

SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList1.DataSource = objCommand.ExecuteReader();
DropDownList1.DataTextField ="score_time";
DropDownList1.DataBind ();
objConnection.Close ();


DropDownList1.Items.Insert(0,"全部");
DropDownList1.SelectedIndex=DropDownList1.Items.IndexOf(li1);


//****************************************************************


//string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL2 ="exec change_ondep '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_dep + "'";

//SqlConnection objConnection=new SqlConnection (strConnection);
objCommand=new SqlCommand(strSQL2,objConnection);

objConnection.Open ();
DropDownList2.DataSource = objCommand.ExecuteReader();
DropDownList2.DataTextField ="dep_name";
DropDownList2.DataBind ();
objConnection.Close ();

DropDownList2.Items.Insert(0,"全部");
DropDownList2.SelectedIndex=DropDownList2.Items.IndexOf(li2);


//******************************************************************


string strSQL3 ="exec change_onclass '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + str_class + "'";

objCommand=new SqlCommand(strSQL3,objConnection);

objConnection.Open ();
DropDownList4.DataSource = objCommand.ExecuteReader();
DropDownList4.DataTextField ="class";
DropDownList4.DataBind ();
objConnection.Close ();

DropDownList4.Items.Insert(0,"全部");
DropDownList4.SelectedIndex=DropDownList4.Items.IndexOf(li4);


//************************************************************


string strSQL4 ="exec change_oncou '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_cou + "'";

objCommand=new SqlCommand(strSQL4,objConnection);

objConnection.Open ();
CheckBoxList1.DataSource = objCommand.ExecuteReader ();
CheckBoxList1.DataTextField ="cou_name";
CheckBoxList1.DataBind ();
objConnection.Close ();



}

private void DropDownList4_SelectedIndexChanged(object sender, System.EventArgs e)
{

ListItem li1=DropDownList1.SelectedItem;
ListItem li2=DropDownList2.SelectedItem;
ListItem li3=DropDownList3.SelectedItem;


//*****************************************************************


string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec change_onscore_time '" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_score_time + "'";

SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList1.DataSource = objCommand.ExecuteReader();
DropDownList1.DataTextField ="score_time";
DropDownList1.DataBind ();
objConnection.Close ();

DropDownList1.Items.Insert(0,"全部");
DropDownList1.SelectedIndex=DropDownList1.Items.IndexOf(li1);


//**********************************************************


//string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL2 ="exec change_ondep '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_dep + "'";

//SqlConnection objConnection=new SqlConnection (strConnection);
objCommand=new SqlCommand(strSQL2,objConnection);

objConnection.Open ();
DropDownList2.DataSource = objCommand.ExecuteReader();
DropDownList2.DataTextField ="dep_name";
DropDownList2.DataBind ();
objConnection.Close ();

DropDownList2.Items.Insert(0,"全部");
DropDownList2.SelectedIndex=DropDownList2.Items.IndexOf(li2);


//******************************************************************


string strSQL3 ="exec change_ongrade '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList4"] +"','" + str_grade + "'";

objCommand=new SqlCommand(strSQL3,objConnection);

objConnection.Open ();
DropDownList3.DataSource = objCommand.ExecuteReader();
DropDownList3.DataTextField ="grade";
DropDownList3.DataBind ();
objConnection.Close ();

DropDownList3.Items.Insert(0,"全部");
DropDownList3.SelectedIndex=DropDownList3.Items.IndexOf(li3);


guyking 2005-01-23
  • 打赏
  • 举报
回复


private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(label_isstu.Text=="学生")
{
string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec Tstu_oncou '" + Request.Form["DropDownList1"] + "','" + label_user.Text + "'";

SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
CheckBoxList1.DataSource = objCommand.ExecuteReader ();
CheckBoxList1.DataTextField ="cou_name";
CheckBoxList1.DataBind ();
objConnection.Close ();

}
else
{

ListItem li2=DropDownList2.SelectedItem;
ListItem li3=DropDownList3.SelectedItem;
ListItem li4=DropDownList4.SelectedItem;


//***************************************************************


string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec change_ondep '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_dep + "'";

SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList2.DataSource = objCommand.ExecuteReader();
DropDownList2.DataTextField ="dep_name";
DropDownList2.DataBind ();
objConnection.Close ();

DropDownList2.Items.Insert(0,"全部");
DropDownList2.SelectedIndex=DropDownList2.Items.IndexOf(li2);


//*****************************************************************************


//string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL2 ="exec change_ongrade '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList4"] + "','" + str_grade + "'";

//SqlConnection objConnection=new SqlConnection (strConnection);
objCommand=new SqlCommand(strSQL2,objConnection);

objConnection.Open ();
DropDownList3.DataSource = objCommand.ExecuteReader ();
DropDownList3.DataTextField ="grade";
DropDownList3.DataBind ();
objConnection.Close ();

DropDownList3.Items.Insert(0,"全部");
DropDownList3.SelectedIndex=DropDownList3.Items.IndexOf(li3);


//**************************************************************************


string strSQL3 ="exec change_onclass '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + str_class + "'";

objCommand=new SqlCommand(strSQL3,objConnection);

objConnection.Open ();
DropDownList4.DataSource = objCommand.ExecuteReader ();
DropDownList4.DataTextField ="class";
DropDownList4.DataBind ();
objConnection.Close ();

DropDownList4.Items.Insert(0,"全部");
DropDownList4.SelectedIndex=DropDownList4.Items.IndexOf(li4);


//******************************************************************


string strSQL4 ="exec change_oncou '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_cou + "'";

objCommand=new SqlCommand(strSQL4,objConnection);

objConnection.Open ();
CheckBoxList1.DataSource = objCommand.ExecuteReader ();
CheckBoxList1.DataTextField ="cou_name";
CheckBoxList1.DataBind ();
objConnection.Close ();


}



}

private void DropDownList2_SelectedIndexChanged(object sender, System.EventArgs e)
{

ListItem li1=DropDownList1.SelectedItem;
ListItem li3=DropDownList3.SelectedItem;
ListItem li4=DropDownList4.SelectedItem;


//****************************************************************


string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL ="exec change_onscore_time '" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_score_time + "'";

SqlConnection objConnection=new SqlConnection (strConnection);
SqlCommand objCommand=new SqlCommand(strSQL,objConnection);

objConnection.Open ();
DropDownList1.DataSource = objCommand.ExecuteReader();
DropDownList1.DataTextField ="score_time";
DropDownList1.DataBind ();
objConnection.Close ();

DropDownList1.Items.Insert(0,"全部");
DropDownList1.SelectedIndex=DropDownList1.Items.IndexOf(li1);


//*************************************************************


//string strConnection="server=(local);database=temp;uid=sa;password=;";
string strSQL2 ="exec change_ongrade '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList4"] +"','" + str_grade + "'";

//SqlConnection objConnection=new SqlConnection (strConnection);
objCommand=new SqlCommand(strSQL2,objConnection);

objConnection.Open ();
DropDownList3.DataSource = objCommand.ExecuteReader();
DropDownList3.DataTextField ="grade";
DropDownList3.DataBind ();
objConnection.Close ();

DropDownList3.Items.Insert(0,"全部");
DropDownList3.SelectedIndex=DropDownList3.Items.IndexOf(li3);


//************************************************************************


string strSQL3 ="exec change_onclass '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + str_class + "'";

objCommand=new SqlCommand(strSQL3,objConnection);

objConnection.Open ();
DropDownList4.DataSource = objCommand.ExecuteReader();
DropDownList4.DataTextField ="class";
DropDownList4.DataBind ();
objConnection.Close ();

DropDownList4.Items.Insert(0,"全部");
DropDownList4.SelectedIndex=DropDownList4.Items.IndexOf(li4);


//******************************************************************


string strSQL4 ="exec change_oncou '" + Request.Form["DropDownList1"] + "','" + Request.Form["DropDownList2"] + "','" + Request.Form["DropDownList3"] + "','" + Request.Form["DropDownList4"] + "','" + str_cou + "'";

objCommand=new SqlCommand(strSQL4,objConnection);

objConnection.Open ();
CheckBoxList1.DataSource = objCommand.ExecuteReader ();
CheckBoxList1.DataTextField ="cou_name";
CheckBoxList1.DataBind ();
objConnection.Close ();



}

private void DropDownList3_SelectedIndexChanged(object sender, System.EventArgs e)
{

ListItem li1=DropDownList1.SelectedItem;
ListItem li2=DropDownList2.SelectedItem;
ListItem li4=DropDownList4.SelectedItem;


yadongfile 2005-01-22
  • 打赏
  • 举报
回复
<a href="index_bblb_xx.aspx ? xx=aa " onclick="Session['aaa'] = 'aaa';">aaaaa</a>
在index_bblb_xx.aspx 获得页面参数 然后处理
这样应该灵活点
kaiqiao521 2005-01-22
  • 打赏
  • 举报
回复
你想实现功能,说清楚点
也许没这么麻烦
学习asp.net的资料
http://218.27.204.17/aspnet/a_user.aspx
xiaomaoxia 2005-01-22
  • 打赏
  • 举报
回复
用个隐藏的input,设为服务器端运行, js可以访问它的值,后台代码C#也能访问
chuxue1342 2005-01-22
  • 打赏
  • 举报
回复
up....
seaonce 2005-01-22
  • 打赏
  • 举报
回复
呵呵,楼主不会想像模拟登陆一样进入需要验证的网页吧?

呵呵,如果是这样恐怕难度有些大,呵呵。

JS里面好像不能用SESSION吧,学习一下
luckyprg 2005-01-22
  • 打赏
  • 举报
回复
Session不能用JS实现吧?
guyking 2005-01-22
  • 打赏
  • 举报
回复
我的意思是
一个链接,点一下,生成一个session
但是因为这个连接又是动态生成的,所以不能用Attributes
guyking 2005-01-22
  • 打赏
  • 举报
回复
up
up
up
up
up
bmiracle 2005-01-22
  • 打赏
  • 举报
回复
不知道,你具体想做什么,照本人理解,是这样

些个隐藏域,把值付给隐藏域,然后在通过JS调用。
<input id="ok" type="hidden" runat="server">

.cs
if(Session['aaa']!=null)
{
ok.Value = Session['aaa'].ToString();
}
this.link1.Attributes.Add("onclick","javascript:check()");

.aspx
function check()
{
strValue = ok.value;
}
yistudio 2005-01-22
  • 打赏
  • 举报
回复
try
<a id="link1" href="index_bblb_xx.aspx" runat="server">aaaaa</a>

page_load
if(!Page.IsPostBack)
{
this.link1.Attributes.Add("onclick",Session['aaa'] = 'aaa');
}
guyking 2005-01-22
  • 打赏
  • 举报
回复
up
up
up
up
up

62,051

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧