如何使用更新/插入按钮单击来验证gridview控件内的文本框?
尊敬的先生,
请告诉我如何使用javascript中的onclinetClick()事件在gridview控件中验证文本框控件.
例如:
源代码:
Dear sir,
Please tell me how to validate textbox control inside the gridview control using onclinetClick() event in javascript.
Ex:
Source code:
<asp:gridview id="grdmenu" runat="server"><FooterTemplate> <asp:TextBox ID="txtbox" runat="server" TextMode="MultiLine">
</asp:TextBox>
</FooterTemplate>
< asp:TemplateField HeaderText ="Edit">
< EditItemTemplate>
< asp:ImageButton ID ="btnMenuUpdate" runat ="server" OnClientClick ="return val();"
文字=更新"/>
</EditItemTemplate>
</asp:TemplateField
>
javascript代码:
<asp:TemplateField HeaderText="Edit">
<EditItemTemplate>
<asp:ImageButton ID="btnMenuUpdate" runat="server" OnClientClick="return val();"
Text="Update"/>
</EditItemTemplate>
</asp:TemplateField
>
javascript Code:
函数val()
{
调试器;
var strin = document.getElementById(<%= txtbox.ClientID%>).value;
}
function val()
{
debugger;
var strin = document.getElementById(<%= txtbox.ClientID%>").value;
}
但这会引发错误吗? "名称"txtbox"在当前上下文中不存在
"
我不知道这是什么错误,请如何获取 txtbox 值到 strin 给我代码..
请回复我
通过mohan
but it will raising error? "The name ''txtbox'' does not exist in the current context
"
I dont know what is the error, please how to get txtbox value to strin give me code..
Please reply me
By mohan
嘿,
更正您的代码有一些语法错误
或按照以下内容替换您的代码
document.getElementById(<%= txtbox.ClientID%>").value;
祝您好运
Hey,
Correct Your code there is some syntax error
or replace your code by following
document.getElementById("<%= txtbox.ClientID%>").value;
best luck
将参数传递给函数val()
并在网格视图中使用参数
调用该函数
< asp:textbox id ="txtbox" runat ="server" textmode ="MultiLine" xmlns:asp =#unknown">
pass parameter to function val()
and call that function in inside gridview with parameter
<asp:textbox id="txtbox" runat="server" textmode="MultiLine" xmlns:asp="#unknown">
请不要使用OnClientClick ="return val ();"
使用以下代码:
在rowdatabound事件中,找到按钮"和文本框的控件.
然后写
Hi, not use OnClientClick="return val();"
Use below code:
at rowdatabound event, find control for Button and text box.
then write
button1.attributes.Add("onclick", "javascript:return val('"+txtBx.ClientID+"');");
现在,在JS函数中,在函数中插入一个参数.
now, in the JS function, insert one parameter in your function.
function val(txtBx)
{
txtBxObj = document.getElementById(txtBx);
if(txtBxObj.value =="")
{
//alert
return false;
}
}
并检查文本框的值.
and check value of textbox.