Auto Ad Code

Showing posts with label parent. Show all posts
Showing posts with label parent. Show all posts

Wednesday, August 11, 2010

Redirecting Parent page from iframe using same query string

Once I got caught in a situation that I had to check Database changes from a hidden iframe placed withing a page and then had to redirect the parent page in a way that parent window don't lose its querystring.
Following was the solution which I used.
========================================
In my main page(testpage.aspx) I had following statement for hidden iframe

<iframe src="refreshpage.aspx?<%= Request.QueryString.ToString %>" style="display: none;"></iframe>


in refreshpage.aspx I was having nothing but a timer and its tick event which was having the code to check in Database that either some new entry has been made or not. And in case there was any new entry I was refreshing the parent page by using Javascript.
Following is the HTML code for the timer part of my refreshpage.aspx.

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="5000"></asp:Timer>

Remember that scriptmanager is must as I am using Timer of AJAX Extensions.

Following is the VB code for refreshpage.aspx.

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If RecordInserted() Then
'RecordInserted is my own function to check if data is enetered or not.
ClientScript.RegisterClientScriptBlock(Me.GetType, "", "<script>window.parent.location.href = ""testpage.aspx?" & Request.QueryString.ToString & """;</script>")
End If
End Sub
====================================

This is it for the code and following is the explanation of above.
refreshpage.aspx checks the database after every 5 seconds that if there is new entry or not and if there is any it refreshes the parent page using Javascript.
<%= Request.QueryString.ToString %> is required in case when QueryString is required for the redirect from iframe.

Hope this will help you :)

Monday, July 12, 2010

Default Button (Enter Key)

Many of us faces the issue that while typing in a textbox we press Enter and expect a button named "A" to be clicked but this doesn't happens and button "B" gets clicked.
For example you have provided a Textbox for Search and a button is given with that textbox so that when that button will be clicked your code will try to search in database for whatever written in Textbox. You expect that when user will press enter while typing in Textbox then search button will be clicked by default but this doesn't happen and instead soneother button (like login etc) get clicked. Pretty much annoyiong is this and even tab sequence don't work here.
Whats the solution?
Its pretty much easy which is to add yout HTML code for that textbox and button withing a <asp:Panel. There is a property named "DefaultButton" for <asp:Panel. You can write ID of your button in the "DefaultButton" property of <asp:Panel. Now whenever Enter key will be pressed in any textbox contained in that <asp:Panel then that button will be clicked whose ID is given against "DefaultButton" property of <asp:Panel.

Sample code
<asp:Panel runat="server" ID="pnlChild" DefaultButton="ButtonID">
    YOUR HTML CODE Including the Button to be Clicked
</asp:Panel>