Showing posts with label application. Show all posts
Showing posts with label application. Show all posts

Wednesday, March 28, 2012

Calling jvascript function from the button under UpdatePanel

Hello,

I am having a a web application developed using asp.net2.0 with vb.net as a language.

In this web application i am having two buttons and one update panel. Now my button1 is outside the updatepanel and another button2 is present inside the updatepanel.

In asp.net if we want to run any javascript function on the click of a button then we normally use the button.attribute.add() function but if we want that when user click on button then first some server side code will be performed and then the javascript function will be called.

For that we uses the below code in asp.net !!!

Page.ClientScript.RegisterClientScriptBlock(Me.GetType,"Script", "<Script>alert('Hello');</Script>")

this code is working fine on the click event of the button that is present outside the update panel. But when i am running the same code on the click event of the button that is present inside the updatepanel then its not working,

Remeber that i d't want to run the javascript code when user just click on the button , i want first some server side code wil perform his work then after this script will run.

But for controls under update panel its not working.??

please paste your code here, because I am doing almost the same thing here without any issues.


Hi,

Add a Literal control to your web form.

In your Click method use this code:

literal1.Text = "<script type=\"text/javascript\"> alert('Hello world!');</script>";

Dont forget to clear Text property in another postbacks.


Use ScriptManager.RegisterStartupScript, instead of the ClientScript class' method.


Can anyone tell me the solution for this?

Me too getting the same issue.

Thanks,

Jasmeeta.

Calling function on Codebehind from client side scripting using ASP.NET AJAX

Hi,

I'm relatively new to the new avtar of AJAX. I've used the Ajax.dll in my previous application to make an AJAX call.

Now my issue is. How do i call a function on my code behind page , from my client side javascript. To elaborate this consider the following.

I'm creating a new ASP.NET AJAX Web Site.

I've Defaul.aspx with following controls.

1. a button.

2.a dropdown.

In my Default.vb page i've a function FillComboValues() that returns a string.

No on clicking Button i wanna run the FillComboValues() function on my code behind.( I DONT WANT TO USE UPDATEPANEL.)

I've read many articles on net to solvemy problem but every example describes how to access a webservice method. none of them have described how to access a pagemethod.

Pls help me out with this ...

Thanks in advance.

----

In previous version of ajax , we needed to register the server side function using <Ajax.AjaxMethod()> _ . isn't there an equivalent way of registering the function.?

Hi,

Same problem for me, plz let me know whether you have found a solution for this or not?

Thanks


Hi, you can only call static functions of codebehind from javascript normally. Create a static function in codebehind and in javascript just call it in the following way:

say your static method is returning some string value, then in javascript you have to write,

var returnedValue = <% ="'" + ReturnHello() + "'" %>


In order to call a function on codebehind you can use either a WebService or an static method. I had the same problem and i used static methods because it′s more like Ajax.AjaxMethod, The first thing to do is to add to the scripmanager the following line EnablePageMethods="true" and then in code behing put [WebMethod] in front of every method you want to use. To call them from your client script, just use PageMethods.[your method name] and you should be good to go....


i am speaking about the code behind file of aspx page (not asmx-webservice). You can not use [WebMethod] in codebehind file.

In previous version of ajax , we needed to register the server side function using[Ajax.AjaxMethod()] {in codebehind} . isn't there an equivalent way of registering the function.?

Pleaes let me know if you have any thing equivalent to this?


SaiTej:

i am speaking about the code behind file of aspx page (not asmx-webservice). You can not use [WebMethod] in codebehind file.

In previous version of ajax , we needed to register the server side function using[Ajax.AjaxMethod()] {in codebehind} . isn't there an equivalent way of registering the function.?

Please let me know if you have any thing equivalent to this?

Alternate method inAjax Extensions is putting the control (for ex:button) in Update panel. All the events that u write for this control are async.

So no need to declare explicitly[Ajax.AjaxMethod()]


asj:

Equivalent way inAjax Extensions is putting the control (for ex:button) in Update panel. All the events that u write for this control are async.

So no need to declare explicitly[Ajax.AjaxMethod()]

calling external javascript functions/ library from within an update panel

I have an application with a large number of javaScript functions that reside in external .js files. User controls that reference these files work perfectly.

When usercontrols inside updatepanels call the external javascript functions and libraries, they fail with 'object not found' errors.

I tested using the scriptmanager.registerclientscriptblock by adding a concatenated string with a simple function and it worked. But this is a bad way to do things both from a debugging standpoint as well as ease of code. There must be a better way?

Dim scriptTextAsString

scriptText = _

"function prepareToClose() {"

& _

"alert('prepare to close');"

& _

"test();"

& _

" }"

System.Web.UI.ScriptManager.RegisterClientScriptBlock(

Me.btnLoad,Me.GetType(),"prepare_close", scriptTextTrue)

btnLoad.Attributes.Add(

"onCLick","prepareToClose(); return false;")

What is the best way to do this?

Unless someone has a better solution, here is what I did. Basically, I load the external file into a string and use the rgisterScriptBlock...everything works well and there is still just 1 instance of the scripts for easy maintenance and other non-ajax pages can use them. Here is the code for anyone interested.:

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Me.btnClose, Me.GetType(), "objectives", regLongScript("objectives.js"), True)


...

Private Function regLongScript(ByVal incoming_name As String) As String
Dim objStreamReader As IO.StreamReader
Try
Dim file_name As String = ""
file_name = Request.PhysicalApplicationPath & "a\js_scripts\" & incoming_name
objStreamReader = File.OpenText(file_name)
Return objStreamReader.ReadToEnd()

Catch ex As Exception
Return ""
Finally
objStreamReader.Close()
End Try
End Function


Here's how I've been doing it:

ScriptManager.RegisterStartupScript(

UpdatePanelTest,

UpdatePanelTest.GetType(),

"keyValue",

"alert('test')",

true);


Here's how I've been doing it:

ScriptManager.RegisterStartupScript(

UpdatePanelTest,

UpdatePanelTest.GetType(),

"keyValue",

"alert('test');",

true);

Saturday, March 24, 2012

Calender Control

Hi,

i am using ajax controls in asp.net.and the problem is with calender control,when i run the application the controls goes behind the text boxes.so whats will be he solution???

Regards ASAD

Just a quickie idea but what if you change the z-index in the styles? will that help?


Hi Asadikram02,

Has your problem been resolved yet ? This kind of issue often occurs on select control and we resolve it by identify its z-index property. Here is the Article which shows the solution. http://support.microsoft.com/default.aspx?scid=kb;en-us;177378

<script>
function setindex()
{
div1.style.zIndex=text1.value;
select1.style.zIndex=text2.value;
getindexes();
}

function getindexes(){

text1.value=div1.style.zIndex;
text2.value=select1.style.zIndex;
text3.value=5;
}
</script>
Above is a sample to set the z-index for a select control. It is similar to your problem.

If it doesn't work , please post your simple sample which contains this issue. Thanks

Best regards,

Jonathan

Wednesday, March 21, 2012

CalendarExtender with ImageButton problem........

In this application,when you press the ImageButton ,the calenda will show; when you press the ImageButton again or select a date ,the calenda will disappear..

But what I wanna realize is that ,when you click the rest of the page ,the calenda will also disappear, how to realize that??

Thank you very much!!!!!!!!!

Default.aspx

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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">
<title>Untitled Page</title>
<link href="http://links.10026.com/?link=StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br /><br />
<b>Calendar with associated button:</b><br />
<asp:TextBox ID="Date3" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Calendar_scheduleHS.png" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="Date3" PopupButtonID="Image1">
</ajaxToolkit:CalendarExtender>

</form>
</body>
</html>

Hi liuyan,

This is an issue of the Ajax Control Toolkit that is known for a while now.

It is even something that will be fixed in an upcoming release of the Toolkit.

You should check the website. This is a direct link to the Issue you talk about.http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=7571

Look at the comments on that site: They include a workaround for this issue until it is fixed in the upcoming release.

Hope this helps!
Kind regards,
Wim


Hi liuyan,

For you situation, I think the easiest way is when hide the Calendar manually when OnClientDateSelectionChanged event occurs. Here is the sample you can refer to:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"
Format="yyyy-MM-dd" PopupButtonID="Button1"OnClientDateSelectionChanged="function hideCalendar(calendar) { calendar.hide(); }">
</ajaxToolkit:CalendarExtender>
<asp:Button ID="Button1" runat="server" Text="Calendar" />

I hope this help

Best regards,

Jonathan

CalendarExtender problem in production server

Hello:

I've a strange problem with CalendarExtender Control. When I'm designing web application on my computer, this control works perfectly. When the textbox for date got focus, calendarextender shows correctly etc...

So, my problem is when I upload my Published Web to production server (with ajax installed, and net framework 2.0 etc..) and I navigate on the web, calendar extender returns to me an error "Object doesnt support this property or method."

I don't understand which is the difference between my computer and production server. I have same installed (excluding visual studio Net on production server, of course)

Web Application consist (to simplify) in one script manager, one update panel wich two textbox with calendarextender inside and a gridview)


Could you help me? Any ideas??

Thanks!


Xabi

Has someone already installed the ASP.NET AJAX Extensions on the production server?


In addition, please also check is there any difference between the configurations on two server's IIS.

CalendarExtender Position

I am trying to use the CalendarExtender Control in my existing VB.net web application .

Downloaded the latest version of Ajax toolkit and included in the project.

I am using the control inside a Table as below..

My page is too long to fit in a screen. so this date field is at the bottom of the page. So if i scroll the page and selects this calender control,

the postion is lost. popup shows somewhere else. Also this control goes under the ListBoxes which is already there in the page.

What should i do to make the popup calender appear on the relative postion of the TargetControl and on top of other controls ?

In the documentation it says popupup should appear with the targetcontrol ..

<TD>

<asp:textboxid="_dt"runat="server"cssclass="data"columns="16"maxlength="16"></asp:textbox>

<asp:labelid="Label70"runat="server"cssclass="label3"text="(dd-mon-yyyy hhmm)"></asp:label>

<asp:ImageButtonid="btn_dt"Runat="server"ImageUrl="calendar.jpg"CausesValidation=false></asp:ImageButton>

<ajaxToolkit:CalendarExtenderID="calendarButtonExtender"runat="server"TargetControlID="_dt"

PopupButtonID="btn_dt"Format="dd-MMM-yyyy hhmm"/>

</TD>

THanks

-Roopa

Hi Roopa1,

roopa1:

Also this control goes under the ListBoxes which is already there in the page.

To resolve this , you should reference to thez-index.

roopa1:

Showing position issue.

I have tested it with a your code and add blank <tr> above the CalendarExtender. And it works fine on IE7 and Firefox. So would you please provide a simple sample here?

Hope this help.

Best regards,

Jonathan