Passing value from popup window to parent form's TextBox - asp.net

Work on ASP.NET Visual Studio 2008 C#. I have a page. From this page I need to call a page on popup. On the popup page selected value will be set on the parent page text control.
One parent page
One child page.
Call parent to child as popup.
On popup window contain a grid.
On popup grid have command select,click on select close popup and selected value will set on parent page text control.
I have done steps 1,2,3 and 4. But I need to complete step no 5.

On parent page:
<script type="text/javascript">
function f1() {
window.open("child.aspx");
}
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><input type="button" onclick="f1();" value="pop up" />
On child page:
<script type="text/javascript">
function f2() {
opener.document.getElementById("TextBox1").value = "hello world";
}
</script>
<input type="button" value="return hello world" onclick="f2();" />
Also you can pass ID of control which you want fill from child page as GET parameter:
window.open("child.aspx?controlID=<%=TextBox1.ClientID %>");

Related

Position radalert next to button that opens it

I have a master page with RadWindowManager in it.
In a child page, there are multiple buttons. On clicking each a radalert message pops up, but it shows in center of page and I would like to show it to immediate right of the button.
How would I make sure that radalert popup shows to immediate right of the clicked button? Bottom of radalert should align with bottom of clicked button.
Use JavaScript to move the dialog when you open it. Something like:
<asp:Button ID="Button1" Text="open RA" OnClientClick="openRA(this); return false;" runat="server" />
<script type="text/javascript">
function openRA(btn)
{
var oAlert = radalert("message");
var btnPos = $telerik.getBounds(btn);
oAlert.moveTo(btnPos.x + btnPos.width, btnPos.y - oAlert.getWindowBounds().height);
}
</script>

Set the style of a parent DIV to a usercontrol

I have a dynamically named DIV in a GridView which contains a user control with a dynamically assigned Parent_ID. The javascript is used to show or hide the DIV. I'll show you two examples of different rows without the ASP code.
Row 1 showing for Order # 123456:
<a href="<%#"javascript:collapseExpand('Order_Notes_Panel123456');" %>" >+</a>
<div id='Order_Notes_Panel123456' style="display:none;">
<uc:Comments_Control id="Comments_Control_ID" runat="server" Parent_ID='123456'/>
</div>
Row 2 showing for Order # 678901:
<a href="<%#"javascript:collapseExpand('Order_Notes_Panel678901');" %>" >+</a>
<div id='Order_Notes_Panel678901' style="display:none;">
<uc:Comments_Control id="Comments_Control_ID" runat="server" Parent_ID='678901'/>
</div>
The good news is that the user control binds and works perfectly. The javascript shows (sets the style to "display:block;") and hides (style set to "display:none;") the appropriate DIV each time the '+' is clicked.
Here is my problem: there is a 'Reply' link in the user control that, when clicked, does a post-back and puts the control into Edit mode. When I employ this user control on another page without a containing DIV, you won't notice a thing. However, when the 'Reply' does its post-back, the containing DIV reverts back to style="display:none;".
Can you provide a recommendation how to set the parent DIV's style to "display:block;" while a user is obviously working with it? I would imagine the appropriate code would go in the code behind of the user control when it goes into Edit mode.
Thanks,
Rob
Update: I recognize that there is no runat=server in my DIV. Since I'm trying to establish a dynamic ID for each, I get an error if I try to use the runat. That is probably the reason why I can't reach it from code behind...
I am very happy of myself... (see the YouTube video for this phrase, you'll be glad you did.)
In summary, this is what I added:
1. New Javascript function to add the name of the target DIV to a hidden field (The "collapseExpand" function is in the Site.Master. I couldn't put "load_div_to_hidden" in the Site.Master since "myhiddenField" isn't set up on every page
2. New hidden field to capture the name of the target DIV
3. New Javascript function to run on window.onload, check if we've got a post-back, and then display the value from the hidden field
4. Adding second Javascript call from the href in the link
Below are the new snippets of code:
<script type="text/javascript">
function load_div_to_hidden(obj) {
var hidden = document.getElementById('<%= myhiddenField.ClientID %>');
hidden.value = obj;
}
function windowOnLoad() {
var isPostBack = (('<%= IsPostBack %>').toLowerCase() == 'true') ? true : false;
if (isPostBack == true) {
var hid_field_value = document.getElementById('<%= myhiddenField.ClientID %>').value;
var right_div = document.getElementById(hid_field_value);
right_div.style.display = "block";
}
}
window.onload = windowOnLoad;
</script>
<input type="hidden" id="myhiddenField" runat="server" value="" />
<a href="<%#"javascript:collapseExpand('Order_Notes_Panel123456'); javascript:load_div_to_hidden('Order_Notes_Panel123456');" %>" >+</a>
<div id='Order_Notes_Panel123456' style="display:none;">
<uc:Comments_Control id="Comments_Control_ID" runat="server" Parent_ID='123456'/>
</div>
Works like a charm!

Modal Popup on Dynamic Button

In my Web application, I am dynamically adding a Button named as "Click Me !". At Stage 1 , when the Button is clicked, it has to show a alert box . At Stage 2, it has to show a Popup.
I use ModalPopupExtender to achieve popup. The Problem is, the popup is just blinked once, instead of Displaying it constantly. Given below my codes...can any one help me to get rid of this ?
Page_OnLoad():
**************
Button Button1=new Button();
Button1.Text="Click Me !";
Button1.ID="LogBut";
Controls.Add(LogBut);
Stage 1:
JavaScript:
***********
function alert()
{
alert("Stage 1");
}
Code behind:
************
LogBut.Attributes.Add("OnClick", "alert();");
Stage 2:
JavaScript:
***********
var Modalpopup='<%=modalPermission.ClientID %>';
function Popup()
{
$find(Modalpopup).show();
}
Design:
*******
<Ajax:ModalPopupExtender ID="modalPermission" runat="server" TargetControlID="Infield"
PopupControlID="divPermission"></Ajax:ModalPopupExtender>
<asp:HiddenField ID="Infield" runat="server" />
Code Behind:
************
LogBut.Attributes.Add("OnClick", "Popup();");
Note: I am using the hidden field control's Id as ModaPopupExtender's TargetControlId. Am adding this button inside calendar control.
Screenshots of the calendar:
Modal popups do not remember that it's supposed to show after a popup. If you are attaching a popup show to a button, you have to disable the postback to the server. Most likely your problem is the button shows the modal, but also posts back, and on postback, the modal doesn't remember it's supposed to show. You can kill the postback by doing the following; set
UseSubmitBehavior='false'
on the server-side button, and then in the Popup function, do:
function Popup(e) {
// stop button event propagation, which causes postback
if (e.stopPropagation)
e.stopPropagation();
if (e.preventDefault)
e.preventDefault();
// show modal
}
And that should prevent a button postback to the server.
EDIT: Your function said Popup, but your javascript is rendering showpopup() as the function call. If that function doesn't exist (and spelled the exact same), it will never stop the postback.

loading image while loading a gridview on runtime

I'm looking for a solution to my problem for two days and I didn't find anything that can help. I have two page : page 1 and page 2
Page1 contains parameters that will be send to page2 and a button "Create"
Page2 contains the GridView and on page_load I have
GetParameters() ; // extract parameters
PrepareParameters(); // prepare local variable
DataTable dt = CreateDataTable(); // create the BoundField/Columns based on prepared local variables
myGridView.DataSource = dt;
myGridView.DataBind();
My problem is that the method PrepareParameters() takes time due to the huge amount of data even though it's optimized. When I click on "Create" button the browser doesn't move to page2 but instead it doesn't respond and stay in page1 and the user does not know what happens.
So I'm wondering how to redirect the browser to page2 and show to the user a loading animation on the grid place until the PrepareParameters() finish processing data and display the GridView once finished?
Thanks for your reply.
You can use Javascript to do that. Get any loader image you prefer, there are many available on net, google it
put this image top/bottom of grid, assign some id to it and set default property Visible = false.
Now on button click call javascript where you make this image visible.
Sample code
<html>
<head>
<script type="text/javascript" language="JavaScript">
function Loading() {
document.getelemanebyId('Img').visibility = visible;
}
</script>
</head>
<body>
<form action="" method="POST" id="myForm">
//Gridview control here
<img id="Img" src="give image file path" runat="server" visible="false"/>
<button name="Create" onClientClick="Loading();" runat="server" >
</form>
</body>
</html>

ASP.NET and JQuery - Default Button Click

I have an ASP.NET page that is basically a search form. My code for this form looks like this:
<form id="mainForm" runat="server">
Search For: <asp:TextBox ID="searchTB" runat="server" />
<input id="myButton" runat="server" type="button" value="Go"
onclick="disableButton(this);" onserverclick="myButton_Click" />
<script type="text/javascript">
function disableButton(b) {
b.disabled = true;
b.value = "Searching...";
}
</script>
</form>
This code works fine as long as a user manually clicks the button. However, if a user hits the "Enter" key, the search is not performed. My question is, how do I set an HTML button to the default button in an ASP.NET page when client-side scripting is involved?
Thank you!
Have you tried the onkeypress event? Bind it to the same function and it should work.
For enter to work by default, your button needs to be the first one on the page and it should be type="submit" rather than type="button".
You could also try changing your input to a standard asp.net button. If you change your javascript function to return true, the post click of the button should still work. However to bind 2 events to the button you may need to add the client side click in your page load method.
myButton.Attributes.Add("onclick", "return disableButton(this)");
ASP.NET 2.0 - Enter Key - Default Submit Button

Resources