Showing posts with label buttons. Show all posts
Showing posts with label buttons. 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.

Monday, March 26, 2012

Callbacks in association with Update panel

I've got a Gridview that I've customized with buttons that do callbacks to get context menus and insert stuff in the main Gridview table.

If I put the entire Gridview in an update panel, what is the likelihood that these little custom callbacks will still work? Rephrased: is it a known feature of update panels that they will interfere with, override, or otherwise mess up such callbacks? Or do update panels just respond to submits, or have some other property, that would indicate that they would not interfere with such callbacks?

Any guidance on this would be appreciated ( I hope to have better luck testing this for myself soon.)

Thanks!

hello.

if i'm not mistaken, the scriptmanager intercepts form submission only...


Thanks for the post. That's good news. I'll keep my fingers crossed for the test.

Agradecimento!

Callback returns wrong SQL results!

I have a page that has buttons to change values in a few tables. When I use Postbacks it works fine, when I AJAXify it it shows the same results as it did before. Here's the strange bit, if I make a second change it shows the expected results from the first change and so on. It seems to always be one change behind.

I'm going to make a very small version of the page and post it here if it still happens.

It is only happening on one table. It is a very large table but I shouldn't think that would matter if the original Postback method works fine.

Does your AJAX.NET enabled page use a full Web Service? If so you install WSE 3.0 and turn on the trace utiliy. This should show what is being sent and recieve.

Saturday, March 24, 2012

Call a WebMethod from javascript (I dont want to use any server side buttons only javascri

I think my problem is slightly different.

I have defined a region of an image using jquery (javascript) I check the click event, it something like onclick for button, so as you can see its all javascript nothing server side button, etc

I want to load a .asmx dynamically in an update panel. I know how to do this using a link button. Now what I want to do is to call a method that load this file in my server code behind.

This is what I tried to do so far. I simplified the problem.

' <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true">
<Scripts>
<asp:ScriptReference Path="JavaScript/loadmypages.js"/>
</Scripts>
</asp:ScriptManager>

'

loadmypages.js is a simple javascript that call my function (i am hoping that it will) through PageMethods. this is a simple style of my javascript.

'

// JScript File

var Load_content2 = function()
{
PageMethods.myfunction_on_code_behind(OnComplete1, OnTimeOut1, OnError1);
return false;
}

function OnComplete1(result)
{
alert(result);
}

function OnTimeOut1(result)
{
document.getElementById('lblMsg').innerHTML ="Time out";
}

function OnError1(result)
{
document.getElementById('lblMsg').innerHTML ="There is an error!";
}

'

I have tried to make my method accesable for javascript like this:

'

using System.Web.Services;

[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public string myfunction_on_code_behind()
{
return "Its good if it works";
}

'

but every time i click on that region the script debugger say PageMethods is not defined.

Could someone help me to solve this problem ? am I missing something here ? as you can see I have even enabled page method: EnablePageMethods="true"

Thank you

Hi,

Please note that the method should be a static method.
Hope this helps.
Can you post your whole webservice file here? I think you are missing something.

Has there been any updates to MS Ajax that don't require PageMethods to use static methods yet?


No, nor would I expect one in the future.