Showing posts with label window. Show all posts
Showing posts with label window. Show all posts

Wednesday, March 28, 2012

How do I integrate 3 party javascripts into Atlas the right way??

I found a great modalpopup window javascript and would like to use it with Atlas.

I guess I could add the script to the Atlas Scriptlibrary and than add it to my we page like this:

<atlas:ScriptManager runat="server" ID="UpdatePanel2"

EnableScriptComponents="True"EnablePartialRendering="True">

<Scripts>

<atlas:ScriptReference Path="~/ScriptLibrary/MyScript.js" />

</Scripts>

</atlas:ScriptManger>

Does this code make the javascript in on my webpage available?

Or I can do it like this:

<script src="http://pics.10026.com/?src=scripts/prototype.js" type="text/javascript"></script>

<script src="http://pics.10026.com/?src=scripts/lightbox.js" type="text/javascript"></ script>

But I would like to work within Atlas. Which brings me to my second question? This javascript uses the prototype.js framework. When I use Atlas do I still need the prototype.js or does Atlas replace those functions?

What I want to know is how do I integrate 3 party javascripts into Atlas the right way?

hello.

you can do it either way...normally, i use the <script> element...

Monday, March 26, 2012

How do I Databind to DropDownListBox with button Onclick

Hi I have javascript calling a webservice which is loading a dataset from an onclick event, which opens a popup window collects information and returns to the main page. I want to just load the data collected from the popup and update the dropdownlist without a postback.

The dataset is loaded and ready to go, I'm not sure how to bind the ds to the dropdown at this point.

Thanks in advance for the help!

Hi

You have an option of populating the DDL using javascript itself by loading the select with options array. But at the cost of not known to the server and not present in view state. If that's okay you can go with that otherwise the good deal would using ajax to load


How would I use ajax to load the dropdownlistbox?


Hi,

Based on my understanding, you opens a popup window to collects information,then you load a dataset based on those information.Where are you loading the dataset? In the popuppage?In the main page?

If you load the dataset in the popup page, It is hard to post your dataset to your main page.

If you just post the collected information to your main page and then load your dataset in the main page, you can do it like this:

place your dropdown contorl in a updatepanel;

pass the collected infoemation to the main page and fire a Ayncpostback to the updatepanel(Loading data from popup to parent window without refreshing the parent window.)

Best Regards,


The update panel will not work as I have 8 independent buttons that need to re populate the different dropdowns on the Main Screen when the Popup closes. Not all the independent buttons are effect the dropdowns at the same time. Is there an extender available that can perform the databind?

Thanks in advance


8independent buttons?

I don't think it is a good design.

Would you please change it?

As far as I know, still no such extender that can perform the databind in that way.


I will create my own extender. Comments on the design are not appreciated, as they are client dictated, and real world...


Hi,

Just a comment...

I think you can pass 8 values to the main page by using "window.opener.document.forms["form1"].elements["xxx"].value = ''".

Happy coding:)

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