Floating Problems

Today I faced with a common issue of using floating html elements on the pages that you may have experienced before.Lets see it in a sample screenshot:The Problem:The right image is floated to the right side of page and the yellow container floats over it :

Before

The Solution:

< img runat="server" style="width: 100%; height: 1px; clear: both; float: none" xsrc="~/images/spacer.gif" mce_src="~/images/spacer.gif" />

After

How can we pass a value between an ASP.NET 2.0 page and its master page?

The routine for passing data around remains similar for new ASP.NET constructs, such as Master Pages. From the aspect of passing data around, the master page acts as a control within the page. So, as with the earlier page/control techniques, to call a public method located within a page’s master page, you must cast the master reference to the exact class name:

Dim MP As MyMasterPage

MP = CType(Me.Master, MyMasterPage)

MP.MyPublicMasterPageSub()

‘The above 3 lines can alternatively be simplified to one:

CType(Me.Master, MyMasterPage).MyPublicMasterPageSub()

To pass data from the master page to the page, the master page should raise an event to the page:

Public Event MasterPageButtonClicked()

Then the event can be raised to the page with a single line of code:

RaiseEvent MasterPageButtonClicked()

The page can handle the event just as if it were coming from a user control:

Private WithEvents _MyMasterPage As MyMasterPage

Private Sub MyMasterPage_ButtonClicked() _

Handles _MyMasterPage.ButtonClicked

Response.Write(”Master page raised button click event.”)

End Sub

Tip:

To access to some controls on the MasterPage you have to create some kind of interface like a function or subroutine to be able to have access to your controls on that master page.

ASP.NET Fails on validating controls when they are disabled from server side by default.

Here is the scenario, I have simple form with some validators bound to them, a check box and a Submit button also a simple Javascript code that checks the checkbox value and then enables the submit button when user clicks on the checkbox. (Traditional “I agree” field or something like that) .

here is the Javascript code:

function agreeClicked()
{
var chk = document.getElementById(”chkAgree”);
var btn = document.getElementById(”btnSubmit”);
if(chk.checked)
{
btn.disabled = false;
}
else
{
btn.disabled = true;
}
}

and here is the code for checkbox:

<input type=”checkbox” onclick=”javascript:agreeClicked()” id=”chkAgree” name=”chkAgree” />

here is the asp.net button code:

<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit” OnClick=”btnSubmit_Click” Enabled=”false” />

The Problem:

when you change the disable an asp.net button from server side, asp.net ignores to generate javascript validation code for the button and when you enable it manually from client side … you will not see any validation check.

The Solution:

do not disable your button from server side then try to disable it from client side when page is loading.

here is a sample code:

<script language=”javascript” type=”text/javascript” >
var btn = document.getElementById(”btnSubmit”);
btn.disabled = true;
</script>