Showing posts with label popupwindow. Show all posts
Showing posts with label popupwindow. Show all posts

Saturday, March 24, 2012

How do I add a popup window within an AJAX UpdatePanel

Hi, I am new to AJAX and trying to figure out the following:

I am trying to display a popupwindow within an AJAX UpdatePanel, but when I used the following code with ajax no popup window appears. When I take it out of the update panel it works fine.

Any help would be much appreciated! Thanks.

PublicSub DisplayMessage(ByVal objPageAs System.Web.UI.Page,ByVal messageAsString) 'Replace end of line characters with JavaScript \n newline character. message = Replace(message, vbCrLf,"\n") message = Replace(message, vbCr,"\n") message = Replace(message, vbLf,"\n") message = Replace(message,"""","\""") 'Replace ugly database tags with (slightly) more meaningful text. message = Replace(message,"[DataDirect ADO Sybase Provider]","Sybase Error:") message = Replace(message,"Native Warning code","Error #:") Dim pageTypeAs Type = objPage.GetType() Dim displayNameAsString ="displayMessage" Dim csAs System.Web.UI.ClientScriptManager = objPage.ClientScript If (Not cs.IsStartupScriptRegistered(pageType, displayName))Then Dim displayTextAsString ="alert(""" & message &""");" cs.RegisterStartupScript(pageType, displayName, displayText,True) EndIf EndSub

#########################################################################

The above code is getting called from the below code.

IfNot IsDate(txtStartDate.Text)Then

DisplayMessage(Page,"Please enter a valid start date.")

ReturnFalse

EndIf

unfortunently, when firing server side functions from inside an updatepanel, it cannot make changes to the page, only to objects on the page that are inside the updatepanel. With this said, trying to write a startup script or any type of javascript block from a updatepanel partial postback will not work, probably for the same reason you cannot use the response.write method. You will either need to deal with the full page postback or handle the popup window in the javascript events.

-ALan


Hi,

to inject JavaScript during a partial postback, you should use the RegisterXXX methods of the ScriptManager control.


Hi Garbin,

Even I' looking for a similar kind issue. and I tried your suggestion, but not getting it properly. I'm getting an exception like

The Script tag registered for tpe 'ASP.sections_events_myPage_aspx' and key 'Key' has invalid characters outside of the script tags: alert();. Only properly formated script tags can be registered.

In the code behind I'm calling the function as

ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "key", "alert();", False)

I think my parameters are not right. Can you give an example of this function or explain its parameters. I saw the doc on msdn but did't understand it perfectly.

Thanks,

Mehul Mistry


Hi,

Can you please check the following...

Dim script As String = "function test()" & _
" { " & _
" alert('test');" & _
" } "

ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "TestFunction", script, True)

I did the above stuff in the method which is called on asyncronous callback in AJAX. It gets executed but there is no alert() msg displayed...

Is this the correct way to do it?

Thanks,

Mehul Mistry


Hiorlash,

I think I figured out the solution.Its working for me. For your situation, What you can do is make a small js file or if you have one then add your window opening javasript function inside the js file. ( Make your javascript function take one string parameter to display your msg from code behind, Like you are doing above ).

Now in you aspx page, you must be having ScriptManager. add one element to the script manager... as follows,

<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Scripts>
<asp:ScriptReference Path="MyJavascriptFile.js" />
</Scripts>
</asp:ScriptManager>

and in the code behind, whichever method is called by the asyncronous call of AJAX, call your function as...

ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "OpenWindow", "fnOpenWindow('myMsg');", True)

This should do the job. Its working for me.

Any better ideas and comment are always welcome :-)


Hiorlash,

Above thing works great... Alternately if you don't want to create a js file then then add your javascript function in your aspx page only in the head section as

<script type="text/javascript">
function fnOpenWindow(myMsg) {
window.open("MyPage.aspx?msg="myMsg,"","scrollbars=yes,statusbar=no,directories=0,status=0,menubar=0,width=605,height=335,left=205,top=205");

// or you can use alert

// alert(myMsg);
}
</script>

and in the DisplayMessage function after you build your message string call the function as

ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "OpenWindow", "fnOpenWindow(' " & message & " ');", True)

This will also work.


Thanks Mehul,

That works great for me now.

Thanks again,
Orla


Hi, sory to pick up the conversation, but i've got the same problem.

Putting the Javascript on an .JS at the head of the control worked for me. The thing is that i'm using a composite control and i had the javascript inside it. By taking the code and creating an .Js i'm creating dependencies for it.

Is there any way to create the .js, but keeping it inside the composite control?

Thank you.

Wednesday, March 21, 2012

How Can i Get the new Values from the PopupWindow in Atlas ModalPopupWindow with samples

if i change the textbox values in Popupwindow and if i click the ok button (ServerSide code) I cant get the new values from the popup window in modalpopupExtender.Anyone Please help me how can i get the new values from the popupwindow in atlas modalpopupExtender.Explain with simple example.

Thanks

Hi,

Try this:

<%@. Page Language="VB" %>

<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Text = DateTime.Now.ToString()
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="always">
<ContentTemplate>
<asp:Panel ID="Panel1" onscroll="javascript:saveScroll();" runat="server" Height="50px" Width="125px" Style="position: static;
overflow: scroll; height: 350px; border: solid 1px blue; background-color: White;
display: none;">
<table border="0" cellpadding="0" cellspacing="0" width="480px">
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Update" OnClick="Button1_Click" />
<asp:Button ID="Button3" runat="server" Text="Close" />
<asp:Button ID="Button4" runat="server" Text="OK" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Panel>
<asp:Button ID="Button2" runat="server" Text="Show" />
<cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1" OkControlID="Button4"
CancelControlID="Button3" TargetControlID="Button2">
</cc1:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>

<script type='text/javascript'>
var scrollLeft = 0;
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args) {
document.getElementById('Button2').click();
setScroll();
}

function setScroll()
{
document.getElementById('<%= Panel1.ClientID %>').scrollLeft = scrollLeft;
}

function saveScroll()
{
scrollLeft = document.getElementById('<%= Panel1.ClientID %>').scrollLeft;
}
</script>

</body>
</html>

Get the value in javascript via "document.getElementById('TextBox1').value".

Best Regards

How Can i get the new values from PopupWindow using Atlas ModalPopupExtender

Hi Friends,

I have completed the part of getting values from gridView and show the values in popupwindow using Atlas ModalPopupExtender.But now my requirement is

i need to edit the values in PopupWindow Textbox.if i edit the values i need to get that new Value.But I cant get it.Pls tell me how can i solve this Problem

Here is my code :

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false"%>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc2" %>
<%@dotnet.itags.org. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="cc1"%>
<%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link href="http://links.10026.com/?link=format.css" rel="stylesheet" type="text/css" />
<link href="http://links.10026.com/?link=default.css" rel="stylesheet" type="text/css" />
<link href="http://links.10026.com/?link=ModalDialogs.css" rel="Stylesheet" type="text/css" />


<title>Untitled Page</title>
<script type="text/javascript">
var clientid;
function fnSetFocus(txtClientId)
{
clientid=txtClientId;
setTimeout("fnFocus()",1000);

}
function fnFocus()
{
eval("document.getElementById('"+clientid+"').focus()");
}
function fnClickOK(sender, e) {
__doPostBack(sender,e);
}
function PopupOrder()
{
setInterval('Popup()', 0);

}



function Popup(str)
{
flag = document.getElementById('hidOrderFlag');
if (flag)
{
if (flag.value == '1')
{
document.getElementById('btnhiddenemployee').click();
flag.value = '0';
}
}
}
</script>

</head>

<body bgcolor="#ebf7fe" style="text-align: center">
<form id="form1" runat="server">
<div>
<atlas:ScriptManager ID="atl" EnablePartialRendering="true" runat="server">
</atlas:ScriptManager>

<div runat="server" id="testdiv" style="text-align: center">
</div>

<atlas:UpdatePanel ID="upd" runat="server" Mode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Enter Last Name to search" Font-Bold =True ForeColor="MidnightBlue"></asp:Label>
:
<asp:TextBox ID="TextBox1" OnTextChanged = "TextBox1_TextChanged" AutoPostBack =true runat="server" Height="20px"
Width="150px" BorderStyle="Solid" Font-Bold="False"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Enter KeyWord"></asp:RequiredFieldValidator>

<br />
<asp:GridView ID="GridView1" runat="server" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="btnEdit" ImageUrl="~/images/Calendar.png" CausesValidation="false" runat="server" OnCommand="CommandButton_OnSelect" OnClientClick="javascript:PopupOrder(); return true;"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="empID" HeaderText="EmpID" />
<asp:BoundField DataField="firstname" HeaderText="FirstName" />
<asp:BoundField DataField="lastname" HeaderText="LastName" />
<asp:BoundField DataField="social" HeaderText="Social" />
<asp:BoundField DataField="department" HeaderText="Department" />
<asp:BoundField DataField="addres" HeaderText="Address" />
<asp:BoundField DataField="phone" HeaderText="Phone" />
<asp:BoundField DataField="appdate" HeaderText="AppDate" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />

</asp:GridView>

</ContentTemplate>
</atlas:UpdatePanel>
<!--cheesy button for the modal popups target control-->



<asp:Panel ID="pnlEmployee" runat="server" CssClass="modalBox" Style="display:none" Width="300px">

<asp:Panel ID="EmployeeCaption" runat="server" CssClass="caption" Style="margin-bottom: 10px; cursor: hand;">
Edit Employee</asp:Panel>
<atlas:UpdatePanel ID="UpdatePopup" runat="server" Mode="Always">
<ContentTemplate>

<asp:HiddenField ID="hidEmployeeEditIndex" runat="server" Value="-1" />

<div>First Name</div><div> <asp:TextBox ID="txtFirstName" runat="server" AutoCompleteType="FirstName" MaxLength="64" Width="250"></asp:TextBox></div>

<div>Last Name</div><div><asp:TextBox ID="txtLastName" runat="server" AutoCompleteType="lastname" MaxLength="64" Width="250"></asp:TextBox></div>


<div>Social</div> <div><asp:TextBox ID="txtsocial" runat="server" MaxLength="64" Width="250"></asp:TextBox></div>


<div>Department</div><div><asp:TextBox ID="txtdepartment" runat="server" MaxLength="64" Width="250" AutoCompleteType="Department"></asp:TextBox></div>

<div>Address</div><div><asp:TextBox ID="txtaddress" runat="server" MaxLength="64" Width="250"></asp:TextBox></div>

<div>Phone</div><div><asp:TextBox ID="txtphone" runat="server" MaxLength="64" Width="250"></asp:TextBox></div>

<div>AppDate</div><div><asp:TextBox ID="txtappdate" runat="server" MaxLength="64" Width="250"></asp:TextBox></div>

<div class="clearer">
</div>

<div><asp:Button ID="btnSaveEmployee" runat="server" Text="Save" UseSubmitBehavior="False" CausesValidation="true" OnClick="btnSaveEmployee_Click"/>
<asp:Button ID="btnCancelEmployee" runat="server" CausesValidation="false" Text="Cancel"/></div>
<input id="first" type="hidden" runat="server" />
<input id="last" type="hidden" runat="server" />
<input id="social" type="hidden" runat="server" />
<input id="department" type="hidden" runat="server" />
<input id="address" type="hidden" runat="server" />
<input id="phone" type="hidden" runat="server" />
<input id="applicationDate" type="hidden" runat="server" />
</ContentTemplate>
</atlas:UpdatePanel>
</asp:Panel>

<input type="hidden" runat="server" id="hidOrderFlag" value="1" />
<input type="button" id="btnhiddenemployee" runat="server" style="display:none" onserverclick="btnhiddenemployee_ServerClick1"/>


<cc1:ModalPopupExtender ID="MyExtender" runat="server">
<cc1:ModalPopupProperties TargetControlID="btnhiddenemployee" PopupControlID="pnlEmployee" OkControlID="btnSaveEmployee"/>
</cc1:ModalPopupExtender>


<atlas:AutoCompleteExtender ID="AutoCompleteExtender1" DropDownPanelID="testdiv" runat="server">
<atlas:AutoCompleteProperties Enabled="true"
MinimumPrefixLength="1"
TargetControlID="TextBox1"
ServicePath="~/Services/ProductService.asmx"
ServiceMethod="FindProducts" />
</atlas:AutoCompleteExtender>
</div>
</form

</body>
</html
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using AjaxControlToolkit.Design;
using AtlasControlToolkit;
using AtlasTextBoxAutoComplete.SQlQuery;

public partial class _Default : BasePage
{

// Db Declaration

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["EMP"].ConnectionString);
DataSet ds = new DataSet();

protected void Page_Load(object sender, EventArgs e)
{

// btnSaveEmployee.OnClientClick = String.Format("fnClickOK('{0}','{1}')", btnSaveEmployee.UniqueID, "");

GridView1.Attributes.Add("Init", "fnSetFocus('" + txtFirstName.Text + "');");
GridView1.Attributes.Add("Init", "fnSetFocus('" + txtLastName.ClientID + "');");
btnSaveEmployee.OnClientClick = String.Format("fnClickOK('{0}','{1}')", btnSaveEmployee.UniqueID, "");
if (conn.State == ConnectionState.Open) conn.Close();
conn.Open();
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{

if (TextBox1.Text != "")
{
Bind(this.TextBox1.Text);
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;
Bind(this.TextBox1.Text);

}
protected void CommandButton_OnSelect(object sender, EventArgs e)
{


ImageButton btnEdit = sender as ImageButton;
GridViewRow row =(GridViewRow)btnEdit.NamingContainer;

hidEmployeeEditIndex.Value = Scrub(row.Cells[1].Text);
txtFirstName.Text = Scrub(row.Cells[2].Text);
txtLastName.Text = Scrub(row.Cells[3].Text);
txtsocial.Text = Scrub(row.Cells[4].Text);
txtdepartment.Text = Scrub(row.Cells[5].Text);
txtaddress.Text =Scrub(row.Cells[6].Text);
txtphone.Text = Scrub(row.Cells[7].Text);
txtappdate.Text = Scrub(row.Cells[8].Text);


}

public void Bind(string lastname)
{

if (conn.State == ConnectionState.Open) conn.Close();
conn.Open();
SqlCommand cmd = new SqlCommand("SP_GetEmployees", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@dotnet.itags.org.lastname", System.Data.SqlDbType.VarChar, 255));
cmd.Parameters["@dotnet.itags.org.lastname"].Value = lastname;
SqlDataReader reader = cmd.ExecuteReader();

DataTable dt = new DataTable();

DataColumn dc0 = new DataColumn();
dc0.ColumnName = "empID";

DataColumn dc1 = new DataColumn();
dc1.ColumnName = "lastname";

DataColumn dc2 = new DataColumn();
dc2.ColumnName = "firstname";

DataColumn dc3 = new DataColumn();
dc3.ColumnName = "social";

DataColumn dc4 = new DataColumn();
dc4.ColumnName = "department";

DataColumn dc5 = new DataColumn();
dc5.ColumnName = "addres";

DataColumn dc6 = new DataColumn();
dc6.ColumnName = "phone";

DataColumn dc7 = new DataColumn();
dc7.ColumnName = "appdate";

dt.Columns.Add(dc0);
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
dt.Columns.Add(dc4);
dt.Columns.Add(dc5);
dt.Columns.Add(dc6);
dt.Columns.Add(dc7);

ds.Tables.Add(dt);

while (reader.Read())
{


DataRow dr = dt.NewRow();
dr["empID"] = reader.GetValue(0).ToString();
dr["lastname"] = reader.GetValue(1).ToString();
dr["firstname"] = reader.GetValue(2).ToString();
dr["social"] = reader.GetValue(3).ToString();
dr["department"] = reader.GetValue(4).ToString();
dr["addres"] = reader.GetValue(5).ToString();
dr["phone"] = reader.GetValue(6).ToString();
dr["appdate"] = reader.GetValue(7).ToString();

dt.Rows.Add(dr);
}
reader.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
}

protected void btnhiddenemployee_ServerClick1(object sender, EventArgs e)
{
hidOrderFlag.Value = "1";
}
//protected void btnSaveEmployee_OnClick(object sender, EventArgs e)
//{
// SqlCommand cmd = new SqlCommand("update tblemployee set firstname= '" + txtFirstName.Text + "',lastname='" + txtLastName.Text + "',social='" + txtsocial.Text + "',department='" + txtdepartment.Text + "',addres='" + txtaddress.Text + "',appdate='" + txtappdate.Text + "' where empID = '" + hidEmployeeEditIndex.Value + "'");
// cmd.Connection = conn;
// cmd.ExecuteNonQuery();
// Bind(this.TextBox1.Text);

//}



protected void btnSaveEmployee_Click(object sender, EventArgs e)
{

// txtFirstName.Text = "SDFSD";
// first.Value = txtFirstName.Text;



//first.Value = Pa
first.Value = txtFirstName.Text;
//last.Value = txtLastName.Text;
//social.Value = txtsocial.Text;
//department.Value = txtdepartment.Text;
//address.Value = txtaddress.Text;
//phone.Value = txtphone.Text;
//applicationDate.Value = txtappdate.Text;


}
protected void txtFirstName_TextChanged(object sender, EventArgs e)
{


}
}

Hirajivisa84 ,

One solution is to register hidden fields and set those fields in a javascript function. That javascript function would be tied to your OnOkScript attribute of your ModalPopupExtender and so would be called whenever your OkControlId control is clicked. That javascript would set the hidden fields to the values of the fields in the modal popup.

Later, you can click a button that fires the code-behind handler that would read those hidden fields.

Here is an example that works:

<%@.PageLanguage="C#"AutoEventWireup="true"Codebehind="Default.aspx.cs"Inherits="AJAXEnabledWebApplication1._Default" %>

<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml">

<headid="Head1"runat="server">

<title>Untitled Page</title> </head>

<bodystyle="background-color: transparent">

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"/>

<div>

</div>

<asp:ButtonID="Button1"runat="server"Style="position: absolute; left: 119px; top: 322px;"

Text="Show Popup"Width="86px"/><asp:ButtonID="Button2"runat="server"Style="position: absolute; left: 277px; top: 198px;"

Text="Read Hidden Value"Width="137px"OnClick="Button2_Click"/>

<cc1:ModalPopupExtenderID="ModalPopupExtender1"runat="server"PopupControlID="Panel1"

TargetControlID="Button1"OkControlID="OkButton"CancelControlID="CancelButton"OnOkScript="SaveTextBoxValue()">

</cc1:ModalPopupExtender>

<asp:PanelID="Panel1"runat="server"Height="183px"Width="199px"Style="left: 36px;

position: absolute; top: 123px"BackColor="#C0FFFF">

<asp:TextBoxID="TextBox2"runat="server"></asp:TextBox>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<asp:ButtonID="CancelButton"runat="server"Text="Cancel"/>

<asp:ButtonID="OkButton"runat="server"Text="Ok"/></asp:Panel>

<asp:LabelID="Label1"runat="server"Text="Label"style="left: 302px; position: absolute; top: 160px"></asp:Label>

</form> </body>

</html>

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

namespace AJAXEnabledWebApplication1

{

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

string hiddenValue ="initial value";

Page.ClientScript.RegisterHiddenField("myHiddenField", hiddenValue);

string clientScript =

"<script type=\"text/javascript\"> "

+" function SaveTextBoxValue()"

+" { "

+" document.getElementById(\"myHiddenField\").value = document.getElementById(\"TextBox2\").value;"

+" } "

+"</script>";Page.ClientScript.RegisterClientScriptBlock(typeof(_Default),"MyClientScript", clientScript,false);

}

protectedvoid Button2_Click(object sender,EventArgs e)

{

Label1.Text = Request.Form["myHIddenField"];

}

}

}

In the Page_Load function we register the hidden field "myHiddenField" and also the javascript.

On the page is a Button2 labeled "Read Hidden Value" that when clicked will fire the codebehind to read the registered hidden field into Label1. In your case I think you want to save those values to several variables, which you can do at Button2_Click event handler, or something similar.

Pete


Hi Pete,

thanks for your reply.

first I tried your sample.But I get only theinitial value.I dont know what is the problem really.and Please tell me i need to get the textbox values from PopupWindow when i press the ok button.

Raji


atcually i got the values from gridView for Textbox using the below code.

protected void CommandButton_OnSelect(object sender, EventArgs e)
{

ImageButton btnEdit = sender as ImageButton;


GridViewRow row =(GridViewRow) btnEdit.NamingContainer;
txtFirstName.Text = row.Cells[1].Text;
txtLastName.Text = row.Cells[2].Text;
txtsocial.Text = row.Cells[3].Text;
txtdepartment.Text = row.Cells[4].Text;
txtaddress.Text = row.Cells[5].Text;
txtappdate.Text = row.Cells[7].Text;
}

if i edit or not edit , i need to get the textbox's values from popupwindow for update my database.Please tell me for get the new Textbox values from popupwindow using atlas PopupExtender?? I tried the below for get the TextBox values but i got only null value.I need to get the values correctly.

in aspx:

btnSaveEmployee is for PopupWindow Button :

<asp:Button ID="btnSaveEmployee" runat="server" Text="Save" UseSubmitBehavior="False" CausesValidation="true" OnClick="btnSaveEmployee_Click"/>

Modal PopupExtender :

<cc1:ModalPopupExtender ID="MyExtender" runat="server">
<cc1:ModalPopupProperties TargetControlID="btnhiddenemployee" PopupControlID="pnlEmployee"/>
</cc1:ModalPopupExtender>

Code behind :

protected void btnSaveEmployee_Click(object sender, EventArgs e)
{

// txtFirstName.Text = "SDFSD";
// first.Value = txtFirstName.Text;

first.Value = txtFirstName.Text;

//first.Value = Pa
// first.Value = txtFirstName.Text;
//last.Value = txtLastName.Text;
//social.Value = txtsocial.Text;
//department.Value = txtdepartment.Text;
//address.Value = txtaddress.Text;
//phone.Value = txtphone.Text;
//applicationDate.Value = txtappdate.Text;


}

the first ,last and etc are input hidden.

I need to get the new Values from PopupWindow in ModalPopupExtender.Help Me!!!!!!!!

Thanks

Raji

Thanks.

raji


Hi Raji,

I double checked the code posted, and it partially worked; i noticed when I hit the refresh button the label goes back to being the initial value. So here is an updated version of the codebehind:

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

namespace AJAXEnabledWebApplication1

{

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

Page.ClientScript.RegisterHiddenField("myHiddenField","");

string clientScript =

"<script type=\"text/javascript\"> "

+" function SaveTextBoxValue()"

+" { "

+" document.getElementById(\"myHiddenField\").value = document.getElementById(\"TextBox2\").value;"

+" } "

+"</script>";Page.ClientScript.RegisterClientScriptBlock(typeof(_Default),"MyClientScript", clientScript,false);

}

protectedvoid Button2_Click(object sender,EventArgs e)

{

string hiddenValue = Request.Form["myHiddenField"];

Label1.Text = hiddenValue;

}

}

}

Click on the "Show Popup" button. Type something into the top textbox in the modal popup. click ok. Click on "Read Hidden Value.", which will then show the new text you typed in.

Also, I'm not using the Atlas toolkit at all, only the AjaxControlToolkit version 1.0. And I'm not using "input" HTML tags of type hidden either, just registering hidden fields and reading them in the codebehind.

Pete


hi pete

I tried ur post but i didnt get a result.bec i got sys is undefined error.( using IE 7). however my requirement is also till not solved.

I used atlas ModalPopupExtender for GridView.In textBox i choose anyone item,that related fields displayed in the GridView.In this GridView I have used

Atlas ModalPopupExtender.if i click anyone of the row edit button the corresponding particular row values displayed in all the textbox's in popwindow.

but if i edit the textbox values and after clicking the ok button in the popupwindow I got only the null values.(The code is shown above).my requirement is i need to retrieve that new values from the Popupwindow.bec it helpful for update my database and also update the GridView.

Please help me or anyone knows help me!!!!

Raji



Hi,

I dont know whether your problem is solved. But for you reference i suggest you to gohttp://www.aspdotnetcodes.com/Ajax_ModalPopup_PostBack_GridView.aspx . this article explains the modalpopup in gridview, also with fine source code and example .

thanks