ラベル server の投稿を表示しています。 すべての投稿を表示
ラベル server の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Reset (buttom) Functionality

Can somebody tell me of a robust way to reset controls (server side) on a form using ajax? Not sure if this is clear or not but the issue that I'm having is that I have an update panel that contains about 6-8 controls (drop down lists and text boxes). The text boxes contain ajax watermark extenders. I tried using the standard html reset button however, my watermarks are not coming back as the defautl text for each text box. Instead, the text boxes are just blank.

In addition, when just resetting a text box control in an update panel, if there is a dropdownlist (postback set to no) the drop down list flickers everytime and it is somewhat annoying.

Any advice and information on these two issues would be greatly appreciated.

Thanks

Hasn't anybody solved this?!

I've got a Reset link that calls a client-side javascript function, but I can't reset a watermarked textbox. (I've tried resetting its class attribute and its value, but it then loses its watermark behaviour.)

Any help would be greatSmile


I also am having this problem. It is amazing that nobody has replied!??Smile

Cheers

Reset controls in update panel when error is thrown

Hello fellow developers,

A user enters a value in a textbox and i click a button to get some data, but a server error is thrown.

Is there a way to clear/reset the textbox in an UpdatePanel when there is a server error?

If there is a way, can someone assist in providing me that trick?

Thanks in Advance.

Protected Sub myButton_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles myButton.Click
Try
' Whatever code that I'm trying to run goes here.
' This is the code that my produce the error.
Catch
myTextbox.Text =""
End Try
End Sub


Can't you simply use a try/catch block, and catch the exception? If an exception is thrown reset it to the old value. You can use a hidden label or textbox to store the previous value.


Use this

protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
if (condition)
{
ScriptManager1.AsyncPostBackErrorMessage =
e.Exception.Message;

}
else
{
ScriptManager1.AsyncPostBackErrorMessage =
"An unspecified error occurred.";
}
}


I apologize. My example scenario was not explained the way I originally thought.

The example should be that when using AJAX you want to show an error message AND reset the controls.

If you write code to 'Throw' a custom error message to an alert window, nothing after the 'Throw' gets executed (clearing my textbox).

So my question really should be:

Is there a way, using AJAX, to 'Throw' a custom error message to an alert window and still reset controls? Either on the server or client side.

Thanks.


Protected Sub myButton_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles myButton.Click
Try
' Whatever code that I'm trying to run goes here.
' This is the code that my produce the error.
Catch exAs Exception
ScriptManager.RegisterStartupScript(Page, Page.GetType,"ErrorMsg", "alert('" & ex.Message & "');",True)
myTextbox.Text =""
End Try
End Sub


Thanks Buddha, that's just what I needed.

Resize animation with RoundedCorners

I have

<div id="div2" runat="server" style='width: 300px; height: 200px; background-color: teal; position: absolute;'>

and

<cc2:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server">
<cc2:RoundedCornersProperties Radius="10" TargetControlID="div2"></cc2:RoundedCornersProperties>
</cc2:RoundedCornersExtender>

and

<cc2:AnimationProperties TargetControlID="div1">
<Animations><OnHoverOver>
<Resize AnimationTarget="div2" Width="500" Height="400" />
</OnHoverOver></Animations>
</cc2:AnimationProperties>

and when i hover over div1... only width changes. A bug?

Hi MarekG,

This is a consequence of the way that RoundedCorners works. It will wrap your target control in another div and set the height of the new div to be the same. If the inner height changes it won't propogate to the containing wrapper (i.e. you're resizing the wrapped control, but it's overflow is hidden by its wrapper so you see nothing happen).

Right now there isn't a way to work around this - but I hope to make some modifications to the Animation framework on the next release that will allow you to side step the issue.

Thanks,
Ted

2012年3月24日土曜日

Returning results from a page method call

In my ASP.NET AJAX web site, I am attempting to use Page Methods to return data from the web server. I would like to be able to return the value from a page method like so:

function GetValue()
{
return PageMethods.GetValueFromServer();
}

function ManipulateValue()
{
var myValue = GetValue();

// Do something with myValue
}

Unfortunately, calling a page method requires the use of a callback function. I really need to retrieve the value without having to store it in a global variable in the callback function; is there any way to do this?

function GetValue(){ return PageMethods.GetValueFromServer( function(result){// The result that is returned from server //Now do what ever you would like to do.} );}
Maybe you can try something like this

KaziManzurRashid:

function GetValue()
{
return PageMethods.GetValueFromServer(

function(result)
{
return result;
}

);
}

Maybe you can try something like this


I tried your code, returning the result in the nested callback function (see above), but when I returned to the code that calls GetValue() the value that ends up getting returned is undefined. :-(


Yes that becasue the ajax call is async. it does not wait for the ajax call to complete, why do not you call the GetValue in the Callback?


KaziManzurRashid:

Yes that becasue the ajax call is async. it does not wait for the ajax call to complete,why do not you call the GetValue in the Callback?



Okay, I'm somewhat confused. I call GetValue(), which calls an asynchronous server method and is passed an in-line Javascript callback function. Are you saying that I should, in the callback function, call GetValue() again? If so, won't that just cause an infinite loop?


Sorry let me rephrase. You do not need to call the GetValue again in the callback although doing it will not make it recursive. You can call your desired outer ManipulateValue function in the callback but in that case the ManipulateValue will not again call the GetValue.


KaziManzurRashid:

Sorry let me rephrase. You do not need to call the GetValue again in the callback although doing it will not make it recursive. You can call your desired outer ManipulateValue function in the callback but in that case the ManipulateValue will not again call the GetValue.

Okay, I tried that but still no luck. Here is the code I am using; perhaps you can shed some insight on to what I'm doing wrong? It looks like this is, in fact, causing an infinite loop.

Javascript code:

function PrintDateTime()
{
var dateTimeFromServer = RetrieveDateTime();
$get("myLabel").innerHTML = dateTimeFromServer;
}

function RetrieveDateTime();
{
return GetAjaxValue();
}

function GetAjaxValue()
{
return PageMethods.GetCurrentDateTime(
function (result)
{
return RetrieveDateTime();
}
);
}

C# code:

[WebMethod]
public static string GetCurrentDateTime()
{
return DateTime.Now.ToString();
}


You can do it in the following way:

function GetAjaxValue(){ return PageMethods.GetCurrentDateTime( function (result) { $get("myLabel").innerHTML = result; } );} function showCurrentDateTime(){GetAjaxValue();}

Just call the showCurrentDateTime in your code when you want to show it.


KaziManzurRashid:

You can do it in the following way:

function GetAjaxValue()
{
return PageMethods.GetCurrentDateTime(
function (result)
{
$get("myLabel").innerHTML = result;
}
);
}
function showCurrentDateTime()
{
GetAjaxValue();
}

Just call the showCurrentDateTime in your code when you want to show it.

Thanks for the time you've spent addressing my questions, Kazi. Unfortunately, in my code I really need to return the value in the RetrieveDateTime() function. The code in PrintDateTime() is just used for illustration; I need to do more than just put it in a label. To clarify, here's exactly what I want to do:

var myValue = RetrieveDateTime();

The value is not being displayed on screen but is being used by logic within a JavaScript function. I really just want to be able to call a JavaScipt function and return a value that I can use in the rest of the code.


Hi, Well you have to undertand the nature, it is always. and thats why the best place to assume the value is availabe is the Callback. If you can describe more of your scenerio then I can help.


Hi,

Thank you for your post!

It seems that you have misunderstanding on AJAX and callback.

The result cann't be obtained like this:

var myValue = GetValue();

It must be obtained like this:

function SetSessionValue(key, value)
{
PageMethods.SetSessionValue(key, value,
OnSucceeded, OnFailed);
}

// Callback function invoked on successful
// completion of the page method.
function OnSucceeded(result, userContext, methodName)
{
if (methodName == "GetSessionValue")
{
displayElement.innerHTML = "Current session state value: " +
result;
}
}

// Callback function invoked on failure
// of the page method.
function OnFailed(error, userContext, methodName)
{
if(error !== null)
{
displayElement.innerHTML = "An error occurred: " +
error.get_message();
}
}

For more information about callback and webmethod, seehttp://www.asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx

If you have further questions,let me know.

Best Regards,

Reverse AJAX?

Has anyone tried doing anything RAJAX (asyncronously send from server to client) with .NET? If so, could you point me in the direction of a reference? I need to write a small script or app that waits for messages on the server and notifies a client that a message has been received. I can't find anything out there for Microsoft technologies in regard to this, or even a set of white papers fro RAJAX.

Tim

hello.

i think that this kinf of application is also known as comet. some links that might help you:

http://en.wikipedia.org/wiki/Comet_%28programming%29

http://dojotoolkit.com/

http://dojotoolkit.com/

http://www.ajaxian.com/archives/comet-a-new-approach-to-ajax-applications

2012年3月21日水曜日

rounded corners control problem

Hi, I have tried this code:

<%@dotnet.itags.org. Page Language="C#" %>
<SCRIPT runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Image i = new Image();
Panel pl = new Panel();
PlaceHolder1.Controls.Add(pl);
pl.Controls.Add(i); pl.BorderColor = System.Drawing.Color.Blue;
pl.BackColor = System.Drawing.Color.Blue;
pl.ID = "pnl";
i.ID = "pppp";
i.ImageUrl = "../images/1/1.jpg";
i.Height = 200;
i.Width = 200;
pl.Height = 200;
pl.Width = 200;
AjaxControlToolkit.RoundedCornersExtender rce = new AjaxControlToolkit.RoundedCornersExtender();
PlaceHolder1.Controls.Add(rce);
rce.ID = "bleble";
rce.TargetControlID = pl.ID;
rce.Radius = 6;
}
</SCRIPT>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD id=Head1 runat="server">
</head>
<body>
<FORM id=form1 runat="server">
<DIV>
<?xml:namespace prefix = asp /><asp:ScriptManager id=ScriptManager1 runat="server">
</asp:ScriptManager>
<asp:PlaceHolder id=PlaceHolder1 runat="server"></asp:PlaceHolder>
</DIV>
</FORM>
</body>
</html>

For some reasons the result I got is the image inside a panel, with two blue thin rounded corners rectangles on the top of the image and on the bottom of it.
It didn't make rounded corner image. What is the problem of it? How can I display rounded corners image?

Why dont you try to create the conrol in the front end instead of the code behind.

use the following code that is on the sample and see it works fine. All you have to do is give the Id of the control!

http://www.asp.net/ajax/control-toolkit/live/RoundedCorners/RoundedCorners.aspx


I write my application in a way that for each aspx file there is aspx.cs file. I tried this 100 times and it didn't worked for me. Take the code I wrote and try it yourself. Does it show a rounded corner Image? For some reason, Images are not working for RoundedCornersExtender.

I am looking desperatly for an answer.

RoundedCorners not displaying vertical border

I have the following code for RoundedCorners.
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="500px" >
<div style="padding:10px;text-align:center">
<div style="padding:5px; border:solid black thin;background-color:#B4B4B4;">
ggggggggggggggggggggggggggggg
</div>
</div>
</asp:Panel>
<cc1:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server">
<cc1:RoundedCornersProperties TargetControlID="Panel1" Radius=2 Color="red" />
</cc1:RoundedCornersExtender
This only shows me horizontal border but not the vertical border. It shows me top and bottom border in red. Not left and right. What am I doing wrong?I'm not exactly sure what you mean, but I think you get the borders by replacing the first div tag with:

<div style="padding:10px;text-align:center;border-left:solid 1px red;border-right:solid 1px red"
I did that. It works. Thx. However, there is a gap between bottom horizontal line and left and right vertical lines

RoundedCornersExtender bug

<

ajaxToolkit:RoundedCornersExtenderID="rce"runat="server"TargetControlID="Panel1"Radius="6"Corners="Top"/>

Hi i was trying to use this rounded corner object on this panel below

<

asp:PanelID="Panel1"runat="server"Width="325px"BackColor="white"Height="0px"Wrap="false"HorizontalAlign="Center"></asp:Panel>well i noticed it adds 6 on both sides i just need 6 on the top not at the bottom. so the objects gets bigger then wanted. i just want the top portion to extend not the bottom. I understand if people dynamicly change the roundness like the example but i dont want that extra portion to show up at all. any way to do this thanks.

Hi,

The Panel you try to extend needs to have a minimun height (15px out of my mind). I think is not documented, but I found it just by experience.

It sounds logical to me, because, if I remember correctly, the corners are calculated using your setting and the size of the control to be extended.

Cheers,

Juan


Sorry, just to correct myself:

The extra height you get is the sum of: Extender Radius + Panel Height. If the height is less than the font-size (or any other block element contained into the panel) and you haven't set the display value of the panel as "inline" (by default would be block) you have to add it to the sum instead of the height.


You didnt understand what im saying look at the code below

<DIV class="roundedPanel" id="ctl00_SampleContent_Panel1" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; VERTICAL-ALIGN: top; WIDTH: 330px; PADDING-TOP: 0px; BACKGROUND-COLOR: transparent; className: "><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 6px; OVERFLOW: hidden; MARGIN-RIGHT: 6px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 3px; OVERFLOW: hidden; MARGIN-RIGHT: 3px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 2px; OVERFLOW: hidden; MARGIN-RIGHT: 2px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 1px; OVERFLOW: hidden; MARGIN-RIGHT: 1px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV class="roundedPanel" id="ctl00_SampleContent_Panel1" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; WIDTH: 100%; BORDER-BOTTOM: medium none"><DIV style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; PADDING-BOTTOM: 10px; PADDING-TOP: 10px; TEXT-ALIGN: center"><DIV style="BORDER-RIGHT: black thin solid; PADDING-RIGHT: 5px; BORDER-TOP: black thin solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; BORDER-LEFT: black thin solid; PADDING-TOP: 5px; BORDER-BOTTOM: black thin solid; BACKGROUND-COLOR: #b4b4b4"><IMG id="ctl00_SampleContent_Image1" style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" alt="ASP.NET AJAX" src="http://ajax.asp.net/ajaxtoolkit/images/AJAX.gif" /><BR />ASP.NET AJAX </DIV></DIV></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV><DIV style="FONT-SIZE: 1px; MARGIN-LEFT: 0px; OVERFLOW: hidden; MARGIN-RIGHT: 0px; HEIGHT: 1px; BACKGROUND-COLOR: #5377a9" __roundedDiv></DIV></DIV></DIV></DIV></DIV></DIV>

this is copied from the roundedcorner example from the web. if you look at the div's, the one in the center is the one that has the data. and the ones before and after are the rounded corner builders. look at the margin left values they change from 0 to 6 on the top which gives the curve and the ones at the buttom dont have that, which is what i want . BUT i dont want the buttom ones at all. My object is basicly touching the following object its looks like they are one peace when these empty divs gets in the way and causes the object not to show as one. if that make sense.

basicly if i can say to the roundedcorner object to show only on the top and dont draw the bottom that would the trick but there is no setting for that and the obj dont get an id so i cant hide them after getting the code build.


drewex,

Yes, maybe I misunderstood your question, but you weren't very clear asking it.
You want the "bottom divs" not to be rendered, am I right? Well, the subject of the thread was "RoundedCornersExtender bug", and I was looking for them when thinking about your question. What you are asking for is not a bug fix, is a change in the expected functionality.

Those extra divs are generated by the javascript function that modifies the DOM after the HTML code is served to accomplish the objective of the extender, which is, according to the samples:

"The RoundedCorners extender applies rounded corners to existing elements. To accomplish this it inserts elements before and after the element that is selected, so the overall height of the element will change slightly. You can choose the corners of the target panel that should be rounded by setting the Corners property on the extender to None, TopLeft, TopRight, BottomRight, BottomLeft, Top, Right, Bottom, Left, or All."

Anyway, as you cannot override the Render method of the control to tweak this, and, as you said, you don't have and id or class to customize, I can't see a feasible way to achieve what you want, except to write you own control inheriting a Panel and adding extra divs wherever you want using the new control's Render event.

Regards,

Juan




drewex,

Have you tried experimenting with a wrapper DIV that has a fixed height of TargetControlID.Height+rounded radius and overflow:hidden? I'm thinking this would let RoundedCorners add to both sides, but because of the fixed height of the container, the bottom rounds wouldn't be visible.


I realized its something im never going to change so i create 4 radious rounded corner then went to the html copied the divs pasted in to my code and removed the existing rounded corner. There i go i got the rounded corner i needed only change i did was to add the initial width and id's runat server. then changing the width was easy just had to do it 5 times instead 1 but who cares. :):):)thanks for trying to help i was just suggesting it would be nice to be able to have the option to remove the extra stuff if i wanted it.