I am having a problem with this website I am currently developing. I am trying to fire a button's Click Event after a series of codes in an external js file. please see my codes below:
.ASPX:
<script type="text/javascript">
var btn = $("#<%=btnRefresh.ClientID%>");
</script>
...
<asp:Button ID="btnRefresh" name="btnRefresh" runat="server" Visible="false" Text="btnRefresh" onclick="btnRefresh_Click" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<asp:GridView ID="myGrd" runat="server">...</GridView>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnRefresh" EventName="Click" />
</Triggers>
<asp:UpdatePanel>
.ASPX.CS:
protected void btnRefresh_Click(object sender, EventArgs e)
{
myGrd.DataSource = null;
myGrd.DataSource = GetData();
myGrd.DataBind();
}
.JS:
function Refresh() {
if (btn) {
btn.click();
}
else {
alert('false');
}
}
Basically, what I want to achieve is this:
- Be able to implement my Add, Edit, Delete on the Page. (Functioning now)
- Call the methods in an external JS file to show the popup boxes for Add, Edit, Delete.
- Once successful, call the
Refresh()method and refresh the gridview only. Refresh()method consumes thebtnRefresh_Clickevent from the .aspx.cs page.
I just used the button for that purpose since I don't know what other options I have.
Now my problem is this. My code was able to declare my btn variable from the .aspx page. When it does inside the external .js file, here is how my btn variable looks like:

The compiler goes through the btn.click() line which is supposed to fire the btnRefresh_Click event from the code-behind. However, it doesn't fire up.
Am I missing anything here? Please help me. I've been stuck here for hours.