admin管理员组文章数量:1414628
So I want a Button1 to be clicked when the submit button has been clicked.
Here is the relevant code:
<input id="Submit1" type="submit" value="Search" onclick="javascript:check_user()" />
<script type="text/javascript">
function check_user() {
document.getElementById('<%=Button1.ClientID%>').click();
}
</script>
<asp:Button id="Button1" runat="server" Visible="false" OnClick="Button1_Click"/>
And here is the error I get:
Microsoft JScript runtime error: Unable to get value of the property 'click': object is null or undefined
Does anyone have any ideas as to what the problem might be? I've been tearing my hair out trying to work it out.
So I want a Button1 to be clicked when the submit button has been clicked.
Here is the relevant code:
<input id="Submit1" type="submit" value="Search" onclick="javascript:check_user()" />
<script type="text/javascript">
function check_user() {
document.getElementById('<%=Button1.ClientID%>').click();
}
</script>
<asp:Button id="Button1" runat="server" Visible="false" OnClick="Button1_Click"/>
And here is the error I get:
Microsoft JScript runtime error: Unable to get value of the property 'click': object is null or undefined
Does anyone have any ideas as to what the problem might be? I've been tearing my hair out trying to work it out.
Share Improve this question asked Mar 27, 2012 at 22:46 QuestionableSounderQuestionableSounder 911 gold badge4 silver badges13 bronze badges 2- Why do you need to click two buttons on the client-side? Why not just run the relevant code on the server-side? Is the form posting to a 3rd-party location and you're trying to execute some code on your server as well? – mellamokb Commented Mar 27, 2012 at 22:52
- If you can tell me a way to have input's onclick go to a c# method then I would be grateful (it can never seem to find the method when I try) - otherwise this was the only way I could think to do it. – QuestionableSounder Commented Mar 27, 2012 at 22:58
3 Answers
Reset to default 1Can't you just do it with a single button?
<asp:Button id="Button1" runat="server" Text="Search" OnClick="Button1_Click"/>
Server-side code:
protected void Button1_Click(object sender, EventArgs e) {
// processing code here
}
if you are not limited to java-script you can try using the trigger from jquery like this
<script type="text/javascript">
function check_user() {
$("#<%=Button1.ClientID%>").trigger('click');
//or
$("#<%=Button1.ClientID%>").click();
}
</script>
As you made the button invisible, asp is not rendering the button control in html. (You can check the HTML source). You can create a style and apply it to the asp button once it is rendered at client side to make it invisible.
.MyHiddenButtonStyle{display:none;}// add this in the header in styles
<input id="Submit1" type="button" name="search" value="Search" onclick="javascript:check_user()" />
<asp:Button id="Button1" runat="server" CssClass="MyHiddenButtonStyle" OnClick="Button1_Click"/>
function check_user() {
document.getElementById('<%=Button1.ClientID%>').click();
}
One more thing I have made the submit button as normal button. anyways you are raising a postback event using javascript.
本文标签: cUnable to get value of the property 39click39 object is null or undefinedStack Overflow
版权声明:本文标题:c# - Unable to get value of the property 'click': object is null or undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745165427a2645646.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论