gpt4 book ai didi

javascript - 如何在C#代码后面编写Javascript代码?

转载 作者:行者123 更新时间:2023-11-28 00:14:28 24 4
gpt4 key购买 nike

我正在动态创建文本框,那么如何为文本框“onchange”事件调用下面的 javascript 函数?

<script type="text/javascript">
debugger;
function myFunction() {
var btn = document.getElementById('<%= temp.ClientID%>').value;
var btntemp = document.getElementById('<%= txttemp2.ClientID%>').value;
var val = parseInt(btn) + parseInt(btntemp);
document.getElementById('<%= TextBox1.ClientID%>').value = val;
}
</script>
<asp:TextBox ID="temp" runat="server" onchange="myFunction()"></asp:TextBox>
<asp:TextBox ID="txttemp2" runat="server" onchange="myFunction()"></asp:TextBox>

这里我动态创建textboxex。

Table table = (Table)this.Page.FindControl("PlaceHolder1").FindControl("Table1");
for (int i = 0; i < rowsCount; i++)
{
for (int j = 0; j < colsCount; j++)
{
TextBox tb = (TextBox)table.Rows[i + 1].Cells[j].FindControl("TextBoxRow_" + i + "Col_" + j);
tb.Text = Request.Form["TextBoxRow_" + i + "Col_" + j];

这里我正在获取第一列的文本框值

else if (j == 2)
{
int quantityText;
TextBox quantity = (TextBox)table.Rows[i +1].Cells[j].FindControl("TextBoxRow_" + i + "Col_" + j);

这里我正在获取第二列的文本框值

else if (j == 3)
{
double rateText;
TextBox rate = (TextBox)table.Rows[i + 1].Cells[j].FindControl("TextBoxRow_" + i + "Col_" + j);

这里我动态生成文本框。

private void GenerateTable(int rowsCount)
{
Table table = new Table();
table.ID = "Table1";
PlaceHolder1.Controls.Add(table);
for (int i = 0; i < rowsCount; i++)
{
TableRow row = new TableRow();
row.ID = "Row_" + i;
else if (j < colsCount - 1)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox();
tb.ID = "TextBoxRow_" + i + "Col_" + j;
cell.Controls.Add(tb);
row.Cells.Add(cell);
}

最佳答案

用它来调用后台代码中的 javascript 函数

ClientScript.RegisterClientScriptBlock(myFunction(), "AlertMsg", "<script> 
alert('Inserted successfully');</script>", true)

关于javascript - 如何在C#代码后面编写Javascript代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30587817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com