Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im working on a web app. and i need to call a such type of js function which is using form controls's id . actually i am am familiar to call js function from code behind but those js functions which are accessing form control ids, not able to access. showing error.

error is like this : 'cannot find the button'.

so what i shouls do ? code behind calling process is below-
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "javascript:open_redirect();", true);


and function is this: -

<script type = "text/javascript">
function open_redirect() {


document.getElementById('<%= click_call_button.ClientID%>').click();
}

</script>
Posted

1 solution

Um.
You do realize that the <%= click_call_button.ClientID%> part of that accesses the server variable, pass that to a JS get id and then click the control it finds?

And you want to call that from the server...which isn't going to work.

Why?
I'd just replicate the JS operations on the server side instead of just trying to complicate matters by running a server function (as a result of client activity) which calls a client function to access a server variable and then execute a client operation which almost certainly activates a server function...all of which is while the first operation is trying to build some HTML to send back from the first server call...and so is the second...

I'd sit down, and rethink what I'm doing here, it's getting unnecessarily overcomplicated (and won't work properly anyway).
 
Share this answer
 
Comments
Ashutosh shukla207 26-Dec-15 4:02am    
okay sir . i will remember. but it was needed . there are some other ways to do the same task. but i was looking to stick with this one .


now can u please tell me how to open a new window with Response.Redirect() . because there is no any overloaded function of response.redirect() to open a new tab.

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