Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Wednesday, March 28, 2012

Accordian - Issue

Hi,

I placed a textbox and a button in an Accordian (inside a pane). When i clicked the button and sumbit the form the data in the textbox is gone. It happens only in the first post back. After that there is no issue.

Can someone kindly let me know if it is an issue or am I doing something wrong ? Do I have do some special configuration in the According control to be used effectively ?

Thanks

Rukshan

hi,

could you post .aspx and code behind code please.

thanks,

satish.


Hi Satish,

I had done a mistake in my post ealier. The problem occurs when you put the textbox and the button in a user control and place that user control inside an accordian pane.

Here is the code,

file : testusercontrol.ascx

<%@. Control Language="C#" AutoEventWireup="true" CodeFile="testusercontrol.ascx.cs" Inherits="testusercontrol" %>
<asp:TextBox runat="server" ID="TextBox1" />
<asp:Button runat="server" ID="submit1" Text="submit" />
<asp:Label runat="server" ID="label" ></asp:Label>

file: testusercontrol.ascx.cs

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;

public partial class testusercontrol : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

submit1.Click += new EventHandler(sub_Click);

}

void sub_Click(object sender, EventArgs e)
{
label.Text = TextBox1.Text;
}
}

Here is the page where I have put the above usercontrol (there is no important code in the code behind for the page, so I am not going to put that here )

file: testatlas.aspx

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="testatlas.aspx.cs" Inherits="testatlas" %
<%@. Register src="http://pics.10026.com/?src=testusercontrol.ascx" TagName="testusercontrol" TagPrefix="uc1" %
<%@. Register Assembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Web.UI" TagPrefix="asp" %
<%@. 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"
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:scriptmanager ID="Scriptmanager1" runat="server"></asp:scriptmanager>

<div>
<cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0" Width="100%" Height="100%"

>
<Panes>
<cc1:AccordionPane ID="pane1" runat="server">
<Header>pane1</Header>
<Content>
<uc1:testusercontrol id="Testusercontrol1" runat="server">
</uc1:testusercontrol>
</Content>
</cc1:AccordionPane>

</Panes>
</cc1:Accordion>


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

The issue is when you enter some text on the textbox (which is in the usercontrol) and submit, the label should be populated with whatever you entered, but it does not :(.

It works fine when you put the user control outside of the according control.

Your help is highly appreciated.


Thanks

Rukshan


hi Rukshan,

i tried your code, but problem is i'm gettign error that Sys is not defined. when you run your project see in status bar of browser if you see something like "Done but with errors on page".

i'll try to see if it works.

thanks,

satish.


Hi Satish,

I do not get such an error in the browser.

Anyways, to reproduce the problem all you have to do it create a user control and put a textbox , a label and a button. In the button eventhandler, assign the the text in the textbox to the text property in the label.

Next create a page and put an accordian pane. Place the user control inside the accordian. Run the app.. When you click the button after entering some text in the textbox, idealy you should see that value in the label. But it doesn't . If you put the usercontrol outside the accordian, It works fine.

Hope you got the picture now :D

Thanks

Rukshan


I was able to duplicate your issue. It seems as if the accordion control is not preserving the view state of it's composite controls. I am not a control guru but it seems that accordion should derive from CompositeControl instead of WebControl. This would do two things - help with the view state of the controls and also clean up the design time rendering.

But back to your problem. The work around solution is to do the following if you want the viewstate for your user control maintained:

protected void Page_Init(object sender, EventArgs e) { AjaxControlToolkit.AccordionPane myPane =new AjaxControlToolkit.AccordionPane(); testusercontrol myUC = (testusercontrol)Page.LoadControl("~\\testusercontrol.ascx"); myPane.ContentContainer.Controls.Add(myUC); Accordion1.Panes.Add(myPane); } 

And then just do the following for the accordion in the ASP:

 <cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0" Width="100%" Height="100%"> <Panes> </Panes> </cc1:Accordion>  

Let me know how it goes.


Hi Cloris,


Thanks a lot, you solution works. Wonder what made it preserve the viewstate when the controls are added in code.

Anyways, it solves the problem. :D


Thanks again!

Cheers

Rukshan


I am not sure what caused this problem. I have been using the Accordion as my intro to web controls. I think it has something to do with the control and how it keeps track of where it's data is coming from - a datasource or the panes tags. When it tries to make the decision to reload the panes from the tags, it is not getting what it expects from the view state. So it just reloads the panes from scratch - killing the viewstate. There is some work that needs to be done in CreateChildControls and elsewhere. Definately a work in progress. The Accordion does function fine when attached to a datasource though.


Hi

Im new to this, i still dont get how this works? So do you HAVE to have your bits within a . ascx control in each pane and not just have a button to do something within the pane?

Also what do you need to put into your asp part of code so it knows where to look.

Thanks
Adam


Hi Adam,

You can just put your stuff within the pane. No need ot have a user control.

Thanks

Ruk


Thanks Ruk

But how do i set the code above to apply for my button control and not a usercontrol as explained earlier?

Thanks

Adam


Hi Adam,

I'm not sure if I understood your question properly, but I hope the following code would help

aspx file :

<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:Accordion ID="Accordion1" runat="server" SelectedIndex="0">
<Panes>
<cc1:AccordionPane runat="server" ID="pane1" >
<Header>
Pane 1
</Header>
<Content>

<asp:Button ID="Button1" runat="server" Text="Button" />
</Content>

</cc1:AccordionPane>
</Panes>
</cc1:Accordion>
</div>
</form>

code file :

protected override void OnInit(EventArgs e) {base.OnInit(e); Button btn = (Button) Accordion1.Panes["pane1"].FindControl("Button1"); btn.Click +=new EventHandler(btn_Click); }void btn_Click(object sender, EventArgs e) { Response.Write("Clicked me ! "); }
 
 
Thanks
Ruk 

That worked great, thanks!

Adam


Ok. But can you imagine this scenario.

1. First time I hit my page I render all accordion panes, with desired controls in it. Picture, Ajax.Rating control, ...)

2. Now I change some Rate in one of my panes. Page does PostBack

3. Now I can insert that rate in database, print message, do some logic...

4.problem: (I want everything that I binded in step 1 to see again after page is partially updated (I have Update Panel that wrap my accordion), That means I do not want again to bind my accordion panes, because this can be very time consuming!!!

5. My accordion does not show up.

Question: Am I missing something or have I logic error in my scenario?

Regards, Veroljub

Accessing Controls From JavaScript

What is the syntax for accessing control form javascript? I can't seem to find it anywhere - I thought it was something like

dunction HideOne(n)

{

var ele = Sys($(n))

}

not a lot to go on with what you have provided but...

assuming that "n" in this context is the id of an element you want to "access" or get then you should use "$(n)"
to avoid issues with that statement... in your example you would remove the Sys() part and only have the $(n) part

this all depends on, however, how you are creating your elements. if you are using the xml-script declarative approach then you might be better off using the $object() function.
the $object() function searches the current markup context for the element, then traverses the tree up to the Application level to try to find the element.
this is different than the $() function which is nothing more than a shortcut for "document.getElementById()"

this allows the ATLAS runtime to have (or support) multiple elements with the same "id" without violating the HTML 4.1 specifications stating "an elements id must be unique" which it clearly would be (in the current context)

hope that helps... if not try adding some more of your code so we can get a better understanding of what you are dealing with


That was perfect thanks.

Monday, March 26, 2012

Access amazon Webservice by javascript in pure html form

I am developing pure html form,

in that i want to show amazon webserice where i dont have any server side, so alternatively

i used some javascript but it is not succesfull,

any one have idea in accessing amazon webservice in javascript ,

You might want to check the Amazon forums. I'm sure they might be able to assist you more with questions regarding their WebService. You could also try checking Google Groups and Yahoo! Developer Network.

http://developer.amazonwebservices.com/connect/forumindex.jspa?categoryID=1



It is not possible to call Amazon WebService from JS Directly due to the Cross Domain. To resolve it create a web service (Which acts as a proxy) which inturn call the amazon webservice. and from JS call your Webservice.


Thanks for this great and amazing simple indian Ajax solution, Pragash.T.


Thanks To every Body ,

i found the solution using iframe tag we can do this , sample code for amazon dvd ads.

<iframesrc="http://rcm-uk.amazon.co.uk/e/cm?t=amazo04-21&o=2&p=36&l=bn1&mode=dvd-uk&browse=501778&fc1=000000<1=&lc1=3366FF&bg1=FFFFFF&f=ifr"

marginwidth="0"marginheight="0"width="600"height="520"border="0"frameborder="0"

style="border: none;"scrolling="no"></iframe>

The url to achieve this ishttps://affiliate-program.amazon.co.uk/gp/associates/login/login.html/202-5683437-3533413

Regards

Pragash.T

Insoft,Chennai

Wednesday, March 21, 2012

A form, a treeview, a update panel, and required field validator.

Ok. Lets see if I can explain this. I have a treeview in a uppdate panel. It has an "Add User" node and some "Users" nodes uder it(Siblings). I have a "Add/Edit User" form in the page, inside a panel inside a update panel. This form has a submit command button and the fields have required field validators. These validators are in a ValidationGroup with the submit button. It''s set up so that when a user clicks the "Add User" node, the form panel is made visible so that a new user can be added. When you click on a particular users node, the users information is loaded into the fields and the panel is set to visible so you can edit the users information.


Here's the issue:

When you select the "Add User" node on the tree the blank fields load and all is good. If after that you click on a users node, the users info is loaded into the fields as it should, and that update panel is updated, but all the validators fire. So, selecting a node in the treeview causes the validation to fire even though they are grouped with the Submit button. I expected the validation grouping would solve the issue, but it didn't. Now I'm stumped. Just staring at it.?Any ideas? Anyone?


Thanks,

CL

One issue could be that treeviews aren't supported in updatepanels... We have noticed some strange issues when we were trying to get one work. You may also want to make sure that everything else has causes validation set to false.
Thanks for your reply. I'll look into the causes validation thing and see if that works.
mdenn, you're a dang genius. That worked. Thanks a bunch.

A form tag with runat=server must exist on the Page to use SetFocus() or the Focus propert

Hi there,

I have a Multiview control with Views. Right now I'm trying to set focus to a textbox using the Activate event of one of the Views, like this:

protected void vieSearchShipment_Activate(object sender, EventArgs e)
{
this.Setfocus(tbxShipment);
}

This is my Setfocus method:

protected void Setfocus(TextBox textBox)
{
(this.Master.FindControl("ScriptManager1") as Microsoft.Web.UI.ScriptManager).SetFocus(textBox);
}

But when I call the Setfocus() method from the View's Activate event, I get this exception:

A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.

The textBox is inside the View and is visible, of course. So what am I missing?

Thanks in advance,

-Benton

Check your <form ... > to see if you miss the runat=server or not.

WS


hi

i got error when i use focus property like this

error:

Invalid operation Exception Unhandled by user code,

A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.


my code:

protected void Page_Load(object sender, EventArgs e)
{
this.lgnUsers.Focus();
}

please help me



See the answer to your other post inthis thread.