ServerTags don't work in OnClientClick
-
02-10-2019 - |
문제
<asp:button runat="server" Text="Save as" OnClick="btnSave_click"
OnClientClick="if(!Check('<% # tb.ClientID %>')) return false; return Object();"
CausesValidation="false"></asp:button>
<asp:TextBox runat="server" ID="tb"></asp:TextBox>
Server tags don't work here. I spend a 1-2 hours to find some way to make this work, but i didn't find anything.
Server tags works in:
<OnClientClick="JSFunc();"
<script type="text/javascript">
function JSFunc()
{
var el = document.getElementById('<% # tb.ClientID %>');
//some actions with el here
}
</script>
or something others with c#.
Is There no way to make server tags working inline? (first example)
ps. Sorry for the bad English
해결책
Using an expression builder, you don't need to call databind and you can inline this quite easliy.
see here
다른 팁
first off in your javascript it should be:
<%= tb.ClientID %>
Note the "=" sign
Secondly, you will also have to call DataBind()
Method on your page_load if you wish to do it inline.
제휴하지 않습니다 StackOverflow