Saturday, June 18, 2011
Page is null at the c# class library control
Just caught up in the mess when I came to see : the parent page of one of my class library control was null at runtime. That means the call:
Page.ClientScript.GetWebResourceUrl([control-type],[full-resource-url]);
would fail.
I have been suggested this happens when my parent page is being rendered within an iframe. But this was not the case for now. I was just using a placeholder to dynamically add the control. So what's the solution?
Yes it came around after some googling, try this:
(Page)HttpContext.Current.Handler).ClientScript.GetWebResourceUrl([control-type],[full-resource-url]);
What's in here?
The Page that refers to the Page control containing this dynamic control is achieved through current request handler. This avoids the problem since the request was generated by the page. But mere Page or this.Page or this.Parent.Page or whatsoever might have been missed due to the hierarchy of the controls or is it due to anything else?
Hope this helps. Sweet programming!
Friday, December 31, 2010
Request.Url - Asp.Net Path Details
And Happy New Year 2011.
Here is my self-note to save my day googling!
Request.Url
Full URL : http://localhost:2000/virtual_dir/myrep/page.aspx?q=qvalue
| Request.ApplicationPath : | /virtual_dir |
| Request.CurrentExecutionFilePath : | /virtual_dir/myrep/page.aspx |
| Request.FilePath : | /virtual_dir/myrep/page.aspx |
| Request.Path : | /virtual_dir/myrep/page.aspx |
| Request.PhysicalApplicationPath | d:\Inetpub\wwwroot\Websitename\virtual_dir\ |
| Request.QueryString : | /virtual_dir/myrep/page.aspx?q=qvalue |
| Request.Url.AbsolutePath : | /virtual_dir/myrep/page.aspx |
| Request.Url.AbsoluteUri : | http://localhost:2000/virtual_dir/myrep/page.aspx?q=qvalue |
| Request.Url.Host : | localhost |
| Request.Url.Authority : | localhost:2000 |
| Request.Url.LocalPath : | /virtual_dir/myrep/page.aspx |
| Request.Url.PathAndQuery : | /virtual_dir/myrep/page.aspx?q=qvalue |
| Request.Url.Port : | 2000 |
| Request.Url.Query : | ?q=qvalue |
| Request.Url.Scheme : | http |
| Request.Url.Segments : | /virtual_dir/ myrep/ page.aspx |
Source: http://www.xcess.info/request_url_parameters_details_asp_net_aen.aspx
Thursday, December 31, 2009
Happy New Year 2010!

Hey World, Happy New Year 2010!
Enjoy your holidays. Forget all the odds of 2009 and plan meaningful life for 2010!
Wherever you spend your holidays this year-end, enjoy it with all your heart. And please accept my warm invitation to spend your holidays of New Year 2011 in Nepal – a world of its own! We are celebrating 2011 as Nepal Tourism Year – 2011. My kind request to add this year into your calendar so that your won’t miss what this mysterious country has to offer you – from Natural beauty to the Mt. Everest, from Hindu’s holy Pashupatinath to Buddhist’s holy Lumbini- the birth place of Lord Buddha, from the miraculous flora and fauna to the diversity of social and cultural property!
Source of photos: Nepal Gallery
Many many happy returns! Happy new year 2010!
Friday, December 18, 2009
Toggle image using jquery for animated hide show in asp-net
Web masters find it attractive to mark or indicate some text in a page as special part. For example a featured product in a shopping cart would hold a finished featured icon image at its side. Similarly we see New image icon blinking at the side of some product or text. It is sometimes better by far to use such animated images to draw user's attention. How would you do this using jquery? The simple answer is that- toggle the image based on its display status, in a regular interval.
There exists a simple method in jquery plugin that accomplished this task:
$('my-image-selector').toggle();
Let's look at the simple example.
<table>
<tr>
<td>This is some test news.</td>
<td style="height:45px"><img id="newImage" src="../images/new.jpg"
alt="New!" height="40px" width="40px"/></td>
</tr>
</table>
<script type="text/javascript">
$(function(){
setInterval(imageFlickr,300);
});
function imageFlickr()
{
$("#newImage").toggle(200);
}
</script>
In the page, I have added an image in a column of a table. Please use your own image (perhaps some 'New' image, as in the image above). Note the javascript setInterval() method that calls the function imageFlickr() every 300ms. In the method, we have the line:
$("#newImage").toggle();
The $(selector).toggle(interval) method toggles the show/hide property of the element. In the code, I haven't used the interval argument of toggle method. The interval in milliseconds defines the fade-in or fade-out speed of the element. Try this once and you will see great effect:
$("#newImage").toggle(200);
You are warmly welcome to share your experiences. You can start discussion by adding comments from the form below. You can help spreading out the words by bookmarking this article to
any of your favourite bookmarking site!
Happy Programming!
Wednesday, December 2, 2009
Prevent page postback on enter key press in textbox in asp-net web page
In an asp.net web page, you may have experienced that pressing enter key postbacks the page. For example, take the following scenario:
<table>
<tr>
<td>Name</td>
<td><asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Email</td>
<td><asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnOK" runat="server" Text="OK" />
</td>
</tr>
</table>
In the page, if you press enter key in any of the textboxes, the page will postback, which is not desired.
1.0 What’s the reason?
Lets look at the html markup generated for the page:
The asp.net button control has been rendered with “submit” type, which is the reason of page postback when enter key is pressed in any of the textboxes. Note the following line in the image above:
<input id="btnOK" type="submit" value="OK" name="btnOK"/>
2.0 The Way Out
We can use two different approaches to prevent postback on enter key-press in any of the textboxes:
1. Using UseSubmitBehavior="false" in the asp.net button control’s markup
We can set UseSubmitBehavior="false" in the button markup:
<table>
<tr>
<td>Name</td>
<td><asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Email</td>
<td><asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnOK" runat="server" Text="OK" UseSubmitBehavior="false" />
</td>
</tr>
</table>
This stops rendering the button as type=”submit”. Now the rendered markup for the button will be:
Not the following line in the image above as captured from firebug:
<input id="btnOK" type="button" onclick="javascript:__doPostBack('btnOK','')" value="OK" name="btnOK"/> This shows that there is no more type="submit" attribute, rather onclick="javascript:__doPostBack('btnOK','') has been added. So you have successfully stopped the page postback now!
2. Prevent enter key press in all the textboxes
One another way to stop the page postback is to prevent enter key press in any of the textboxes. We can use jquery to easily perform the task. This way:
<script type="text/javascript">
$(function(){
$(':text').bind('keydown',function(e){ //on keydown for all textboxes
if(e.keyCode==13) //if this is enter key
e.preventDefault();
});
});
</script>
On page load, all the textboxes in the form are bound to the keydown event to a function. In the function we check if the key pressed in the ‘enter key’. If so, we prevent the further bubbling of the event. Hence it prevents the page postback.
Note: You will need to reference the latest jquery file in the page to use the second technique.
3.0 Conclusion
We looked at two ways to prevent page postback on enter-key press in a textbox in asp.net web page. Both the techniques work well. But I would prefer the first one since this would save the extra client side manipulations in the user’s machine.
4.0 Looking towards hearing from you!
You are warmly welcome to share your experiences. You can start discussion by adding comments from the form below. You can help spreading out the words by bookmarking this article to any of your favourite bookmarking site!
Happy Programming!
Popular Posts
-
Most of the times programmers fill the DataTable from database. This action fills the schema of the database table into the DataTable . We ...
-
I have found much tricks in different tutorials and forums on opening new window in asp.net web page, using JavaScript, jquery etc. Here I h...
-
The asp.net Eval() and Bind() expressions are heavily used in asp.net GridView and DetailsView data bound controls. The difference between ...
-
I have oracle database installed in my computer. My Operating system is XP. I wrote an application in asp.net. It connected to oracle databa...
-
Last time I got the following error: HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related ...
-
Last time we talked about Refreshing the parent page from child window in asp.net using javascript . This technique is useful in many scenar...
-
In this post, I am explaining the button click functionality on key press in a textbox. I am using javascript to link the input textbox and ...
-
We do have a folder (and a number of sub folders) with a number of various files in those folders (and sub folders). Now we do need to list ...
-
Much often we open child windows from parent web page . In the child page we perform some activities, and later close the window. At the ver...
-
The default behaviour of asp.net gridview is that it hides both Gridview header and footer when no data is present. You can note the absence...





