JavaScript中的OnClicentclick事件 [英] OnClicentclick event in javascript
问题描述
亲爱的所有人,
我在gridview的页脚中有一个文本框和保存"按钮..
我正在尝试通过表格页脚中的文本框将数据输入表格..
我想为保存按钮编写onclient click事件,以避免将空文本插入到网格中.
在编写此javascript验证时,我将不胜感激..
谢谢..
Dear all,
I have a textbox and save button in the footer of my gridview..
I am trying to enter data to the grid through the textbox in the footer of the grid..
I want to write the onclient click event for the save button to avoid the empty text being inserted to the grid..
i would appreciate any help in writing this javascript validation..
Thanks..
推荐答案
嗨 拉杰什,
我以为:
按钮名称:btnSave
文本框名称:txtAdd
服务器端代码:
Hi Rajesh,
I assumed:
Button Name: btnSave
Textbox Name: txtAdd
Server side code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
btnSave..Attributes.Add("onclick","return checkValidation();");
}
}
Javascript代码:
Javascript code:
function checkValidation()
{
var txt = document.getElementById('<%= txtAddlientID %>');
if(txt.value == '')
{
alert('Please enter data before save!');
return false;
}
return true;
}
如有任何疑问,请让我知道.
请提供"投票":thumbsup:如果有帮助,请提供"接受答案",如果这是正确的答案.:rose:
谢谢,
Imdadhusen
Please do let me know, if you have any doubt.
Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:
Thanks,
Imdadhusen
OnClientClick ="return Isnotesempty()";
OnClientClick="return Isnotesempty()";
function Isnotesempty()
{
if(document.getElementById (objid).value=="")
{
alert("Description should not be empty...!");
document.getElementById (objid).focus();
return false;
}
return true;
}
祝您编码愉快.
Happy Coding.
如果txtbox.text!="然后
如果文本框文本不为空,将执行
if txtbox.text != "" then
will execute if the textbox text is not empty
这篇关于JavaScript中的OnClicentclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!