Reputation: 282
Basically I have three functions embedded into my form. I want to move this into a js file that I have already. I did this previously and my pop ups are working but now I want to move one function which executes the onclick event for a download button and the other two functions belonging to my autocomplete extender so I can display the results how I want them.
I have been messing around but I cannot seem to get this working.
This is my JavaScript function in Web Forms
function Download() {
__doPostBack("<%= btnDownload.UniqueID %>", "OnClick");
}
This is what I have tried in a js file
function Download(button) {
__doPostBack(button, 'OnClick');
}
and this is how I am calling it
ClientScript.RegisterStartupScript(Me.GetType(), "download", "Download(" & btnDownload.ClientID & ");", True)
please can somebody give me a clue to what I am missing and before I forget yes, the file is in my headers
<script type="text/javascript" src="js/importBuyer.js"></script>
Upvotes: 0
Views: 153
Reputation: 133
From the example you've posted it seems that the webform way was sending the UniqueID and you are sending the ClientID So you probably only need to send the UniqueID property instead.
I am wondering why should you do that. I would expect you to move from webforms to an API base backend but I can't understand why you want to separate the js integration part while keeping the webforms backend - I would understand if you'd separated the js logic part... not the part that communicates with the webforms
Hoped that helped
Here is a link describing the difference
Upvotes: 0
Reputation: 2149
The javascript function __doPostBack("<%= btnDownload.UniqueID %>", "OnClick");
expect a string as the client ID of the button. So you need to construct the calling script with ID parameter as string as follows:
ClientScript.RegisterStartupScript(Me.GetType(), "download", "Download(""" & btnDownload.ClientID & """);", True)
Note the double double-quotes (""
) above so that the rendered javascript will be like :
Download("btnDownloadID");
Upvotes: 1