Asp.Net Webforms如果使用按钮是或否,我如何处理? [英] Asp.Net Webforms How Can I Handle If By If With Button Yes Or No?

查看:88
本文介绍了Asp.Net Webforms如果使用按钮是或否,我如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到像这样的 http://www.animalgame.com/play [ ^ ]

在webform问题和课堂内的按钮

示例有一个WebForm有两个按钮是和否

我生成了两个事件。



并且有课程提问



if(yes)

{

// make this

}

//需要停止代码并再次等到按下按钮



if(no)

{

//制作这个

}



点击按钮事件时我传递querystring例如Default?prm = 是

并且在课堂上我得到那个查询字符串例如



if(prm =yes)

$



}



if(prm =no)

{

}

问题是我每次只能选择一次。解决方案

您需要了解网站的工作原理。你的asp.net代码没有在浏览器中运行,它不能等待按钮点击并继续根据结果。您需要向用户显示包含当前问题的表单和yes \ no按钮,并且可能是隐藏字段或视图状态中的当前问题ID。提交表单时,您需要处理yes \ no响应,然后选择下一个问题并再次显示表单。由于您的解决方案涉及多个表单提交,您需要存储其问题的当前状态以便记住它,因此您可能会使用Session ...这将保持它们在逻辑图或列表中的位置过去的答案,无论你需要存储什么来使你的逻辑工作。


I need get somethink like this http://www.animalgame.com/play[^]
In webform questions and buttons in class desicions
Example there is one WebForm with two buttons yes and no
I generated two events.

And have class with questions

if("yes")
{
//make this
}
//need stop code and again wait until pushed button

if("no")
{
//make this
}

In button event when clicked i pass querystring for example Default?prm="yes"
and in class i get that querystring for example

if(prm="yes")
{

}

if(prm="no")
{
}
Problem is i only can chooice one time for every if.

解决方案

You need to gain an understanding of how web sites work. Your asp.net code isn't running inside the browser, it can't wait for button clicks and continue based on the results. You need to show the user a form with the current question and a yes\no button, and probably the current question ID in a hidden field or viewstate. When the form is submitted you need to process that yes\no response then choose the next question and show the form again. As your solution involves multiple form submissions you need to store the current state of their question so that it is remembered, so you'll probably use the Session for this...that will maintain where they are in your logic graph, or the list of past answers, whatever you need to store to make your logic work.


这篇关于Asp.Net Webforms如果使用按钮是或否,我如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆