ShareThis

Showing posts with label ASPX. Show all posts
Showing posts with label ASPX. Show all posts

Thursday, July 19, 2012

ascx control causing shift when viewing page (loading late)

This is a pretty simple fix. The problem is that the control loads late (possibly waiting for the server response to populate its data). The fix is to wrap the controls in a <div> element. Then set the style attribute:

<div id="controlWrapper" style="display:hidden;">
controls
</div>

You can use javascript or jquery to set the display style once the controls have loaded, so they display at the same time and no shifting occurs.

Wednesday, July 18, 2012

How to disable an asp button with runat="server" from javascript

The reason this doesnt work with the asp button's ID is because this ID is not the actual ID on the client side. Instead, you will want to use the button.ClientID.

You can set the client state value of the ClientID on the C# class for the page. In the javascript, you can get the client state value and use jQuery or document.getElementById(...) using the value returned from the client state value.

From there, it is as simple as :



$("#myButton").attr("disabled", "true"); 
$("# myButton ").removeAttr("disabled");


Friday, July 13, 2012

ASP Page Life Cycle Graphic


Thursday, June 21, 2012

[ASP] Get enum int value from aspx markup in javascript

This stumbled me as casting to an (int) in the markup like this did not work:
case <%= (int) MyEnumType.USA %>:
case <%= Int32.Parse(MyEnumType.USA) %>:
The correct usage is with Convert.ChangeType(...) method:

<%= Convert.ChangeType(MyEnum.USA, MyEnum.USA.GetTypeCode()) %>

[ASP] FIX - script5009 'telerik' is undefined - $telerik is undefined

The problem is probably caused by script that assigns $telerik.$ to $ not getting loaded properly after AJAX. The Telerik.Web.UI.dll library has a script you can include through the ScriptManager that does exactly the same. The difference is that you do not have to worry about whether it is properly included with AJAX, because the ScriptManager takes care of that.




Fix: Add the following to your aspx or ascx page.

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    </Scripts>
</asp:ScriptManager>

Wednesday, June 20, 2012

[ASP] FIX - The control with ID requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.


Server Error in '/' Application.

The control with ID 'myIdControlBox' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The control with ID 'RadTextBox1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.





The simple fix to this is to do as it says: add in a ScriptManager before the given control ID.


E.x. (you can copy this directly in to your code):



<asp:ScriptManager ID="ScriptManager1" runat="server" />

Sunday, June 17, 2012

[ASP] Set Asp Literal Style

ASP:Literal is simply rendered text. No style available unless it is defined in the text that is given for the literal; i.e. something like this:
<b> Hello, world! </b>
Would render bold. You can not set a style attribute on the Literal.

If you want to be able to set the style attribute, use an ASP:Label instead. It is rendered text wrapped in a <span> tag which allows for the setting of the style attribute.

This wont work:


<asp:Literal ID="myId" runat="server" style="font-weight:bold;"></asp:Label>


This will work:



<asp:Label ID="myId" runat="server" style="font-weight:bold;"></asp:Label>


Monday, June 4, 2012

Programmatically check javascript enabled aspx

Use the following example:


<script type="text/javascript">
document.write("Hello World!")
</script>
<noscript>Your browser does not support JavaScript!</noscript>


Source