Asp.net、jQuery和动态内容
我有一个asp.net站点,我在其中通过动态方式在DataGrid中创建演示文件。 接下来,我必须检查quantity动态字段中的值是否为null、是否不是数字、是否为负数等等 我想在单击发送按钮时检查它,我想使用jQuery脚本来完成这项工作;问题是:如何检索动态文本框的id?在html页面中,它们每个都有一个前缀,我不想使用循环。 例如:Asp.net、jQuery和动态内容,jquery,asp.net,Jquery,Asp.net,我有一个asp.net站点,我在其中通过动态方式在DataGrid中创建演示文件。 接下来,我必须检查quantity动态字段中的值是否为null、是否不是数字、是否为负数等等 我想在单击发送按钮时检查它,我想使用jQuery脚本来完成这项工作;问题是:如何检索动态文本框的id?在html页面中,它们每个都有一个前缀,我不想使用循环。 例如: protected void DettOrdGridView_RowDataBound(object sender, GridViewRowEventA
protected void DettOrdGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{...
e.Row.Cells.Add(cellQta); //here i add a cell to the row of the grid
...
}
在html页面中:
$(document).ready(function){
$("#btnSaveProvvisorio").delegate("textbox", "change", function(){
var jtbNumBollaQuin;
jtbNumBollaQuin=$('#<%=myTextBoxQta.ClientID%>').text();
alert("Valore quantita : " + jtbNumBollaQuin);
})
}
谢谢大家!
Here the aspx.net code:
protected void DettOrdGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
...
myTextBoxQta = new TextBox();
myTextBoxQta.ID = "myTextBoxQta";
myTextBoxQta.Attributes.Add("nomeTextBox", "myTextBoxQta");
myTextBoxQta.Attributes.Add("runat", "server");
myTextBoxQta.Attributes.Add("onChange", "javascript:TotaliOrdDett();");
myTextBoxQta.Style["text-align"] = "center";
i = e.Row.Cells.Count;
i = i - 1;
//Column label
if (e.Row.RowIndex == -1)
{
if (risultato > 0)
{...
}
else //...add a textbox
{
myOracleConnection = myDbClass.dbConnessione("myconn");
//System.Diagnostics.Debug.WriteLine("Cella: " + e.Row.Cells[0].Text);
myQuery = "SELECT QTA_NR, KG_LORDI FROM TABLE WHERE SOC='1' AND ORD=" + ordHidden.Value + " AND ROW_ORD=" + e.Row.Cells[0].Text;
qtaKgInseriti = myDbClass.EseguiSqlSelect(myQuery, myOracleConnection, qtaKgInseriti);
myDbClass.dbDisconnessione(myOracleConnection);
e.Row.Cells[i].Controls.Add(myTextBoxQta);
cellQta.Controls.Add(myTextBoxQta);
e.Row.Cells.Add(cellQta);
//myTextBoxQta.Text = e.Row.RowIndex.ToString();
if (risultato > 0)
{
myTextBoxQta.Text = qtaKgInseriti.Tables[0].Rows[0]["QTA_NR"].ToString();
txtSumQta.Text = (Int32.Parse(txtSumQta.Text) + Int32.Parse(myTextBoxQta.Text)).ToString();
}
e.Row.Cells[i].Controls.Add(myTextBoxKg);
cellKg.Controls.Add(myTextBoxKg);
e.Row.Cells.Add(cellKg);
//myTextBoxKg.Text = e.Row.RowIndex.ToString();
if (risultato > 0)
{
myTextBoxKg.Text = qtaKgInseriti.Tables[0].Rows[0]["KG_LORDI"].ToString();
txtSumKg.Text = (Double.Parse(txtSumKg.Text) + Double.Parse(myTextBoxKg.Text)).ToString();
}
myCompValNr = new CompareValidator();
myCompValNr.ID = "myCompValNr";
myCompValNr.ErrorMessage = "<div style=\"font-size: x-small; text-align: center; color: #FF0000\">Please enter a number grater than zero!</div>";
myCompValNr.ControlToValidate = "myTextBoxQta";
myCompValNr.Type = ValidationDataType.Integer;
myCompValNr.Operator = ValidationCompareOperator.GreaterThan;
myCompValNr.ValueToCompare = "0";
myCompValNr.Display = ValidatorDisplay.Dynamic;
e.Row.Cells[i + 1].Controls.Add(myCompValNr);
myReqFvNr = new RequiredFieldValidator();
myReqFvNr.ControlToValidate = myTextBoxQta.ID;
myReqFvNr.Text = "<div style=\"font-size: x-small; text-align: center; color: #FF0000\">Field Qta cannot be null!</div>";
e.Row.Cells[i + 1].Controls.Add(myReqFvNr);
myCompValKg = new CompareValidator();
myCompValKg.ID = "myCompValKg";
myCompValKg.ErrorMessage = "<div style=\"font-size: x-small; text-align: center; color: #FF0000\">Please enter a number grater than zero!</div>";
myCompValKg.ControlToValidate = "myTextBoxKg";
myCompValKg.Type = ValidationDataType.Double;
myCompValKg.Operator = ValidationCompareOperator.GreaterThan;
myCompValKg.ValueToCompare = "0";
myCompValKg.Display = ValidatorDisplay.Dynamic;
e.Row.Cells[i + 2].Controls.Add(myCompValKg);
myReqFvKg = new RequiredFieldValidator();
myReqFvKg.ControlToValidate = myTextBoxKg.ID;
myReqFvKg.Text = "<div style=\"font-size: x-small; text-align: center; color: #FF0000\">Field Kg cannot be null!</div>";
e.Row.Cells[i + 2].Controls.Add(myReqFvKg);
}
}
并设置myTextBoxQta.CssClass=“MyTextBoxClass”;在aspx.cs文件中
并将ClientMode=“Static”添加到aspx文件中的btnSaveProvvisorio按钮
非常感谢!!!
Igor您可以像这样使用
数据属性
<textarea data-clientId="#<%=myTextBoxQta.ClientID%>" ></textarea>
同时检查页面中是否存在id
myTextBoxQta
的ASP.NET控件。。。控件的标记上可能没有runat=“server”
.on
代替.delegate
- 更新*
myTextBoxQta.CssClass = "MyTextBoxClass";
然后
$(document).ready(function){
$("#btnSaveProvvisorio").delegate("textbox", "change", function(){
var jtbNumBollaQuin;
jtbNumBollaQuin=$('.MyTextBoxClass').text();
alert("Valore quantita : " + jtbNumBollaQuin);
})
}
您的页面上不存在名为myTextBoxQta的ASP.NET控件。。。它上面可能没有runat=“server”。克里斯,我把标签放在:myTextBoxQta=newtextbox();myTextBoxQta.ID=“myTextBoxQta”;添加(“nomeTextBox”、“myTextBoxQta”);添加(“runat”、“server”);添加(“onChange”,“javascript:totaliordett();”;myTextBoxQta.Style[“文本对齐”]=“居中”;啊,我现在明白了。我已经更新了我的答案。
$(document).ready(function){
$("#btnSaveProvvisorio").delegate("textbox", "change", function(){
var jtbNumBollaQuin;
jtbNumBollaQuin=$($(this).data('clientId')).text();
alert("Valore quantita : " + jtbNumBollaQuin);
});
});// check end of document.ready()
myTextBoxQta.CssClass = "MyTextBoxClass";
$(document).ready(function){
$("#btnSaveProvvisorio").delegate("textbox", "change", function(){
var jtbNumBollaQuin;
jtbNumBollaQuin=$('.MyTextBoxClass').text();
alert("Valore quantita : " + jtbNumBollaQuin);
})
}