如何从asp.net中scriptmanager.registerclientscript中编写的javascript确
How to return value from javascript confirm box written in scriptmanager.registerclientscript in asp.net.?
如何从asp.net中scriptmanager.registerlinkscript中编写的javascript确认框返回值。?
事实上,我想在gridview的文本框的文本更改事件上给出确认框。如果用户单击"是",则我希望更新更改后的值;如果用户单击否,则它应该恢复到旧值。
我的伪代码是这样的:
Protected Sub GridViewCreateInvoice_QuantityTextChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim gr As GridViewRow
Dim i As Boolean
Dim txtqty, txtupdatedQty As TextBox
Dim txtoqty, qty As String
Dim result As MsgBoxResult
'Dim dtPOFulfillmentInfo As DataTable
Try
txtqty = DirectCast(sender, TextBox)
gr = txtqty.NamingContainer
'' txtoqty = GridViewCreateInvoice.Rows(gr.DataItem("originalqty")).ToString()
txtoqty = DataBinder.Eval(gr.DataItem, "originalqty").ToString()
qty = DataBinder.Eval(gr.DataItem, "qty").ToString()
If Not ((txtqty.Text = String.Empty And Not txtqty.Text.Trim = "" And Not txtqty.Text.Contains(" ")) And (txtoqty = String.Empty)) Then
If txtqty.Text > txtoqty Then
ScriptManager.RegisterClientScriptBlock(Page, Me.GetType(), "Confirm Quantity Changed", return confirm("Are you sure you want to continue"), True)
If i = True Then
DataBinder.Eval(gr.DataItem, "qty") = txtqty.Text
Else
txtqty.Text = DataBinder.Eval(gr.DataItem, "qty").ToString()
End If
Else
ScriptManager.RegisterClientScriptBlock(Page, Me.GetType(), "Confirm Quantity Changed", return confirm("Are you sure you want to continue"), True)
If i = True Then
DataBinder.Eval(gr.DataItem, "qty") = txtqty.Text
Else
txtqty.Text = DataBinder.Eval(gr.DataItem, "qty").ToString()
End If
End If
End If
Catch ex As Exception
Common.WriteLog(ex.Message)
Common.WriteLog((ex.StackTrace))
Response.Redirect("~/Error.aspx", False)
End Try
End Sub
我建议不要在TextBox
'TextChanged
事件上发布(AutoPostback=true
)。
相反,我建议在客户端进行所有操作。一种方法是处理onchange
事件以显示javascript confirm
,并在用户单击cancel
:时立即恢复旧值
function confirmUpdate(sender,message){
var update = confirm(message);
if(update){
return true;
}else{
sender.value = sender.defaultValue;
return false;
}
}
文本默认值属性
您可以在GridView
:的RowDataBound
服务器端注册此功能
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtqty = (TextBox)e.Row.FindControl("txtqty");
txtqty.Attributes.Add("onchange", "return confirmUpdate(this, 'Are you sure you want to continue')");
}
}
I dont know what else logic you had implemented..
its a simple solution may be it helps u..
put a label for e.g lblScript in your page
then simply set its text from server side i.e
lblScript.Text =
"<script> var x=window.confirm('Are you sure you are ok?')
if (x)
window.alert('Good!') //
else
window.alert('Too bad')
</script>";
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 使用php或javascript从facebook相册URL中删除多余的部分
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在JavaScript中将字符串转换为函数引用
- 模糊事件的Javascript测试
- Javascript更改图标
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何使用WCF服务和javascript表单post上传.doc文件
- javascript结合了数组和字典
- 这是什么 ==- javascript 运算符
- 从javascript创建一个列表
- 无法在通过jQuery的ajax加载的页面中执行javascript
- Javascript:selenium Web驱动程序isDisplayed()不工作
- 如何通过ajax刷新JSF填充的javascript变量
- 如何在Javascript中将JSon对象转换为数组
- Javascript生成的表单未提交
- 使用javascript将动态表从一个html页面打印到另一个html页
- 通过javascript重定向html传递php变量