PDA

View Full Version : [CLOSED] How to read dynamic checkbox value using request.form



debarry
Nov 06, 2014, 8:19 PM
Hi Guys,

Is possible read dynamic checkbox value using Request.Form?

This is my checkbox:


var CheckItemAlternativa = new Ext.Net.Checkbox() { ID = "CK_" + objPer.IdPergunta + "_" + objAlternativa.IdAlternativa,
Name = "CK_" + objPer.IdPergunta + "_" + objAlternativa.IdAlternativa,
FieldLabel = objAlternativa.Label,
Value = "s"};
FieldSetQuestao.Items.Add(CheckItemAlternativa);


This is my code to read all the values from form:
It works with textField, I don't know how to do with checkboxes.



foreach (var control in Request.Form.Keys)
{
Classes.Resposta objResposta = new Classes.Resposta();
//get checkboxes values
if (control.ToString().StartsWith("CK_"))
{
if (!string.IsNullOrEmpty(Request.Form[control.ToString()]))
{
objResposta.Valor = Request.Form[control.ToString()];

listREsposta.Add(objResposta);
}
}

Thank's in advance.

Daniil
Nov 07, 2014, 10:30 AM
Hi @debarry,

Hope this helps.

Example

<%@ Page Language="C#" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.Form.Controls.Add(new Checkbox { ID = "Checkbox1", InputValue = "Some InputValue" });
}
}

protected void Get(object sender, DirectEventArgs e)
{
string s = this.Request["Checkbox1"];
bool check = false;
string inputValue;

if (s != null)
{
check = true;
inputValue = s;
}
else
{
inputValue = "It cannot be read from the Request, because there is no such the information in the Request";
}

X.Msg.Alert("GetByRequest", "Checked: " + check + "<br/>InputValue: " + inputValue).Show();
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Button runat="server" Text="Get" OnDirectClick="Get" />
</form>
</body>
</html>

debarry
Nov 10, 2014, 9:17 PM
You may close the thread.

Thank you.