Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program has a button (btnFilter) to filter the name column. It takes some time and I introduced a Modal popup window upon clicking the same button using the OnClientClick event but it has no effect at all. Please help.

What I have tried:

I tried these coding:

HTML
HTML
<div id="divStatus" class="divUserStatusHide"></div>
    <div id="modal" class="modal" style="background-color:rgba(64,64,64,0.5);width:100%;height:100%;z-index:1000;display:none";></div>
    <div id="wait" class="modal" style="width:300px;height:50px;margin:100px auto 0 auto;display:none;background-color:#fff;z-index:1001;text-align:center;">
     PLEASE WAIT...
</div>

button defined in vb code behind:
VB.NET
btn = New Button
btn.ID = "btnFilter"
btn.CssClass = "btnShort"
btn.Text = com.Convert(Resources.Resource.COMMON_Filter)
btn.Attributes("onclick") = "javascript:document.location='Home.aspx?fid=" & iFID & "&name=' + document.getElementById('txtName').value; return false;"
btn.Attributes("onclientclick") = "javascript:pleaseWait();"        
cell.Controls.Add(btn)
JavaScript
function pleaseWait() {
    document.getElementById("modal").style.display = "block";
    document.getElementById("wait").style.display = "block";
    return true;
}
Posted
Updated 24-Nov-20 22:15pm
v2

1 solution

onclientclick is not an HTML attribute. It is a server-side property used for writing the client-side onclick attribute, working around the fact that the OnClick property wires up the server-side click event.
ASPX
<asp:Button runat="server" OnClick="Server-side click event handler" OnClientClick="Client-side 'onclick' attribute" .../>
You need to put both sets of client-side code in the onclick attribute:
VB.NET
btn.Attributes("onclick") = "javascript:pleaseWait(); document.location='Home.aspx?fid=" & iFID & "&name=' + encodeURIComponent(document.getElementById('txtName').value); return false;"
 
Share this answer
 
Comments
cora chan 25-Nov-20 4:50am    
Thanks Richard, unfortunately it behaves the same way and doesn't have any effect.

I copied the codes from internet and noticed that the popup box within Div is using class="modal", do I need to include any special declarative ?
Richard Deeming 25-Nov-20 5:00am    
You shouldn't do - it looks like all of the styling is in the style attribute.

Have you tried debugging your code using your browser's developer tools?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900