Calling javascript for a SharePoint webpart?
-
How do I call javascript from a SharePoint webpart. The webpart is just a user defined control ascx file. Where do I register the script section and where do I put the functions? Thanks, Steve Holdorf
-
How do I call javascript from a SharePoint webpart. The webpart is just a user defined control ascx file. Where do I register the script section and where do I put the functions? Thanks, Steve Holdorf
I was told: You can create a Litral control and set the Text property, like following - protected override void CreateChildControls() { Litral scriptLitral=new Litral(); scriptLitral.Text="<script type='text\javascript'>"; scriptLitral.Text+="function CustomAlert(msg){"; scriptLitral.Text+="alert(msg);}</script>"; Controls.Add(scriptLitral); } I tried this but could not add the function to a button control. Can you help?
-
How do I call javascript from a SharePoint webpart. The webpart is just a user defined control ascx file. Where do I register the script section and where do I put the functions? Thanks, Steve Holdorf
If it is an ASCX you can embed the script within the markup. Or you could do it from the code behind using the RegisterClientScriptBlock[^] or RegisterClientScriptInclude[^]
Failure is not an option; it's the default selection.
-
If it is an ASCX you can embed the script within the markup. Or you could do it from the code behind using the RegisterClientScriptBlock[^] or RegisterClientScriptInclude[^]
Failure is not an option; it's the default selection.
Thanks for your help. I can put the script in the ascx file just fine. The problem is that when I try to access document.getElementById('<%# input1.ClientID %>'.value I get the error input not found. It seems that the input control on the ascx can not be found. Thanks, Steve
-
Thanks for your help. I can put the script in the ascx file just fine. The problem is that when I try to access document.getElementById('<%# input1.ClientID %>'.value I get the error input not found. It seems that the input control on the ascx can not be found. Thanks, Steve
Have you debugged? Have you used tools such as IE developer toolbar to inspect the elements? IMO, I would be using JQuery rather than document.getElementById. It is cross-browser and has better functionality.
Failure is not an option; it's the default selection.
-
Have you debugged? Have you used tools such as IE developer toolbar to inspect the elements? IMO, I would be using JQuery rather than document.getElementById. It is cross-browser and has better functionality.
Failure is not an option; it's the default selection.
I am using the IE developer toolbar to try to find my element but it's id is not being found. don't know if document.getElementById works with sharepoint textbox controls. How would you recommend getting the textbox element's value in the javascript? Thanks, Steve
-
I am using the IE developer toolbar to try to find my element but it's id is not being found. don't know if document.getElementById works with sharepoint textbox controls. How would you recommend getting the textbox element's value in the javascript? Thanks, Steve
Of course document.getElementById works with SharePoint. SharePoint is ASP.NET and uses ASP.NET controls, but getElementById is JavaScript and works on the client-side. Perhaps you are not familiar with Dev toolbar operations. Click the HTML tab, then the arrow below it. Move to the IE window to highlight an element and click on it. You should see the details of the rendered element in the tool window. You can the find the ID that has been given to the rendered element. Using JQuery you can find an element using a selector, such as
$("[id$='myElement']")
This will find any element whose id ends with myElement, regardless of the name mangling applied by ASP.NET
Failure is not an option; it's the default selection.
-
Of course document.getElementById works with SharePoint. SharePoint is ASP.NET and uses ASP.NET controls, but getElementById is JavaScript and works on the client-side. Perhaps you are not familiar with Dev toolbar operations. Click the HTML tab, then the arrow below it. Move to the IE window to highlight an element and click on it. You should see the details of the rendered element in the tool window. You can the find the ID that has been given to the rendered element. Using JQuery you can find an element using a selector, such as
$("[id$='myElement']")
This will find any element whose id ends with myElement, regardless of the name mangling applied by ASP.NET
Failure is not an option; it's the default selection.
I used the Dev toolbar and it showed the id of the rendered element as 'txtMsg' which was the actual id in the VS markup. That is what I was using with the getElementById which it could not find. Now, I am confused. Sorry for the problems! Steve
-
I used the Dev toolbar and it showed the id of the rendered element as 'txtMsg' which was the actual id in the VS markup. That is what I was using with the getElementById which it could not find. Now, I am confused. Sorry for the problems! Steve
got it working. Sorry for being a pain in the butt.