How can I write this code:
<script type="text/javascript" id="igClientScript"> function showModalWin(w) { var w = $find('<%= modalwindow.ClientID %>'); w.set_windowState($IG.DialogWindowState.Normal); } </script>
in a separate js file?.
Thaks.
I knew that my surrender would inspire to you
Nice approach and nice solution
Thank you very much.
Since your objective is to move all of your JavaScript code into a separate file, you can make this happen by using a little bit of server-side code.
Instead of using the ClientSideEvents element in the ASPX markup, you can connect the client-side Cick event by using server-side code. For instance, I used the following line of code in the server-side Init event of my WebDialogWindow:
protected void WebImageButton1_Init(object sender, EventArgs e){ WebImageButton wib = sender as WebImageButton; wib.ClientSideEvents.Click = string.Format("showModalWin($find('{0}'));", modalwindow.ClientID);}
With this, I could avoid putting any JavaScript functions directly on my ASPX page.
I've attached a sample project to this post demonstrating what I've done. This sample is written in Visual Studio 2008, targeting CLR 3.5, and using NetAdvantage for Web Client (ASP.NET CLR 3.5) 2009 Volume 1.
Thank you for the help.
I have 2 objectives:
1) Move all my JScript code to a separate files
2) Use client code for showmodalwindow.
I know that this works if i write the function in the aspx page but I don't want this.
I think that the key of all is what you said:
ClientSideEvents Click="showModalWin($find('<%= modalwindow.ClientID %>'));" />
... then the WebDialogWindow reference was not returned - it always entered the showModalWin() function as a null value. This is because the <%= %> substitution doesn't get evaluated in this scenario
So I give up.
I put together a test project, and I believe I see what's going on.
One issue appears to be an issue with registering external JavaScript files when you have a ScriptManager on the page. I used the following line to register my external JavaScript file on my page:<script type="text/javascript" language="javascript" src="WDW_Script.js" />
Initially, I had placed this in the HEAD of the page. This doesn't work in conjunction with a ScriptManager, and caused the ASP.NET AJAX framework to throw a number of errors at me. As a result, none of the ASP.NET AJAX functionality worked, including attempting to get a reference to my WebDialogWindow, yet JavaScript alerts worked fine - a result similar to what you described..
There are two solutions that I've found:
<asp:ScriptManager ID="ScriptManager1" runat="server"> <Scripts> <asp:ScriptReference Path="./WDW_Script.js" /> </Scripts></asp:ScriptManager>
Another issue is with the client-side Click event of WebImageButton. If I set the client-side Click event as follows:<ClientSideEvents Click="showModalWin($find('<%= modalwindow.ClientID %>'));" />
... then the WebDialogWindow reference was not returned - it always entered the showModalWin() function as a null value. This is because the <%= %> substitution doesn't get evaluated in this scenario - nor is it supposed to be.
Instead, I set the client-side Click event of the WebImageButton as follows:<ClientSideEvents Click="WebImageButton1_Click" />
... and declared the following JavaScript function on my ASPX page:
function WebImageButton1_Click(oButton, oEvent) {showModalWin($find('<%= modalwindow.ClientID %>'));}
This worked in my test.
Another alternative would be to set the client-side Click event of WebImageButton using server-side code, where you can get the ClientID property of your WebDialogWindow and substitute that ID to your function call directly.
I hope this information proves helpful.
Sorry, this is because I write the post directly.
When I click on the button I get: Can't eval $find('<%= modalwin.ClientID %>'));