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

Wednesday, March 28, 2012

Programmatically Scroll GridView Control

I have an AJAX enabled web form with several data-filled GridView controls. The users accessing this web app will navigate the site via touch-screen monitors (i.e.: no mouse). As a result, I need an easy way for them to scroll the GridViews when the data is not visible. I want them to click on a button, which will then accordingly scroll the grid up or down. I have tried all the various combinations of the suggestions that I could find:

GridView.Rows(20).RowState = DataControlRowState.Selected

and

GridView.Rows(20).Focus()

and

GridView.SelectedIndex = 20

and

'Set focus to a hidden button control (column)
GridView.SelectedRow.Cells(5).Focus()

If I could set focus to a particular row, I think it should scroll to show that row. This would be fine, but nothing seems to work. Anyone have any suggestions on how I could programatically scroll a GridView control?

Thanks!

Hi AxeRose,

Did you find any solution for this problem?

I have asimilar purpose and meantime I don't have no idea, how to do this.


No, I never found a solution. I ended up using Paging instead -- which works fine for my situation.

Good luck!


I do not know if this works (and probably only in IE or in everything but IESmile ) but there is a javascript function called scrollIntoView that you could try. Just a suggestion.


Seehttp://forums.asp.net/t/1162570.aspx

You can use the JavaScript function: scrollTo(...)

-Damien


<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_beginRequest(beginRequest);

function beginRequest()
{
prm._scrollPosition = null;
}
</script>

http://forums.asp.net/t/1156877.aspx

Monday, March 26, 2012

Progress bar appear when submiting form

I have a contact us form that sends an email.

I want to use an update panel which allows me to do the following:

When the user clicks the send button, form dissapear and progress bar is show for a couple seconds and then notification to the user if email sent ok or not.

I have implemented this using updatepanel and updateprogress but 99% of the time the updateprogress is not displayed because the command is carried out so quick. I would like the progress bar be displayed and give the user the feel of the email being sent. I have the form in a standard panel. How can i make sure the form disappear and updateprogress is displayed?

I have looked at using the updatepanelanimator but it seems difficult to use and think i can do what i want to do without it, correct?

Appreciate any help.

You could approach this a number of ways.. here is probably the quickest and dirtiest way but I don't recommend it:

Add:

System.Threading.

Thread.Sleep(2000);

To your server side processing, this will block the current thread for a specific number of milliseconds forcing the browser and UpdateProgress to wait for the response. Please don't do this. :)

A better way to do this would be to use an animation sequence to give the user the visual feedback that something has taken place, in this case that an email has been sent. The ASP.NET Ajax Animation Toolkit works excellent for this because you can specify the duration for which animations will run... so even if your UpdateProgress and UpdatePanel have completed processing, you could still have an animation still playing before the user moves on to a new action.

Try the animation framework, it's quick to pickup and has some very nice tutorials:http://ajax.asp.net/ajaxtoolkit/Walkthrough/UsingAnimations.aspx

Cheers,
Al

Wednesday, March 21, 2012

Question about using AJAX to load user controls

So I'm making a pretty simple form here, and I need some help. I'll make the content of the problem abstract and just focus on what I'm trying to understand about the language.

I have two different user controls, one is form A and the other is form B. Based on a button that the user clicks (button A or button B), I want to load form A or form B. Only one form can be visible at a time.

I've created the user controls in two separate .ascx files. On the main page, I have an update panel where I placed user control A and user control B.

Currently, the page load handler in the main page sets visibility as form A visibility = false and form B visibility = true. The click handler for button A and button B will set the appropriate visibility options so that you will see form A if you click button A, and form B if you click button B. This seems to be an amateur solution to what I'm trying to do.

Here's my question that I think will lead to me a better solution:

What if I had a much larger collection of user controls? It would become unwieldly to place them all in the updatepanel, so I assume there is a way to not load them all at once. Is there way to place a reference to a 'collection' of user controls in the update panel, and then load them individually based on a user input (such as a drop down list)? Let's say there are hundreds of user controls, and I want to load only a certain one based on user input. What is the best way to do this?

Let me know if I need to clarify my question, and thank you for any answers or explanations!

You can add a PlaceHolder control inside the UpdatePanel. Then you can load the user control using Page.LoadControl method passng the appropriate path for the user control's file. Finally add the loaded user control to the PlaceHolder as a child.


Thanks for the reply! I need some clarification though.

How do I assign a place holder control inside the update panel?

I believe I understand the use of the Page.LoadControl method. Depending on the form they select, you would pass the path of that control as a string to the method.

My last question is how do I add a loaded user control to the place holder as a child?

I'm sorry if these are basic questions, but I'm new to AJAX and web programming in general, so I'm figuring this out as I go.

Thanks again for any responses.


After reading more about what I'm trying to do, I think I know how to do all but the setting of the control as a child within the update panel. Could you elaborate on that? I can't find the correct information via search engine.

I did some more research, and I figured out everything I needed to know. Thank you for pointing me in the right direction! Here is a snippet that captures what I was trying to do.

' Declare a variable named controlToLoad of type Control.
Dim ucPlaceHolderAs Control
' Call the page's LoadControl method passing it the virtual path to
' an ASP.NET UserControl (.ascx file), assigning
' the resulting control object to the ucPlaceHolder variable.
ucPlaceHolder =Me.LoadControl(sControlPath)
' Add the control object to the update panel control container
Me.UpdatePanel.ContentTemplateContainer.Controls.Add(ucPlaceHolder)


I have been tried using

upMainContent.ContentTemplateContainer.Controls.Add(Page.LoadControl(ContentControlPath));

to dynamically load a control into an update panel however, If I do anything in that control which requires a postback, the control just disappears.

Is anyone else experiencing this problem or know how to fix it?


hello.

see if this helps:

http://msmvps.com/blogs/luisabreu/archive/2007/02/15/adding-controls-to-an-updatepanel-through-code.aspx

That C# is a little confusing for me. Could someone give a VB version?

I'm actually having the same problem as one of the above posters. I can't get viewstate to persist across postbacks.

Basically, I have 3 controls. Two of the controls are composits of drop down lists, text fields, and attach, submit, and cancel buttons.

The third control is a menu that will dynamically create one of the two forms based on a button click on the menu.

I register the menu on a aspx page, and then can bring up either form based on a button click in the browser.

I need a way to load the menu again with all of the same field data entered after the user hits the attach button. I would like to keep all the code that dynamically creates forms in the menu control if possible.

Question About Using Validation Controls after a ASYNC postback

I have been working this issue all day and have yet to get anywhere on it so I thought I would try my luck posting something here.

I have a web form users are suppose to complete and save in order to add new records to the database. There are five form fields that have validation controls assigned to them. The validation controls are displayed in a validation summary control. When the user opens an existing record and the form opens all of the form fields are rendered to the page and the validation works fine even inside the ajax update panel. The issue I have is when a new record is being added.

When a user opens the page to add a new record they only see three of the fields on the form. The user has to first select a value from a drop down control which fires are async-postback which in turn displays the rest of the form fields on the page. Just so I am clear the initial three controls displayed are all tied to a validation control. The remaining to controls that are suppose to be validated are part of the form that is hidden until the user selects a value in the first drop down control.

I am having an issue with the two controls that get rendered after the async-postback. The validation controls assigned to these form controls do not fire. After viewing the source code that is rendered to the browser I have determined that the validation controls are created but they cannot find the client-side code for the controls that are to be validated.

When the async-postback is fired from the drop down and the form is rendered to the client why does the client-side source code not show the now unhiddened form fields?

Like I said all the validation controls work when a user edits an existing record because all the fields are shown when the page loads. How do you get the client-side code updated after the async-postback?

I had a similar problem that I had also posted on the forums to get some answers, but I ended doing the research myself and figuring out a solution—take a look at the last post on the thread for a brief description of the problem and solution (http://forums.asp.net/t/1109901.aspx), if you have time.

One thing that I'll point out is the use of the UpdatePanel, and what is actually placed within UpdatePanels. On an Async. PostBack, the UpdatePanels that are configured to respond to an Async. PostBack for a specific trigger (i.e., onchange event of the drop down box) will have th content within them overwritten, updated, or what have you—either way, new HTML is put into the UpdatePanels. The problem here is that any JavaScript referring to HTML elements within one of these UpdatePanels no longer refer to the same HTML elements before the Async. PostBack. What I had to do in this situation is re-hook the JavaScript with thenew HTML elements within the UpdatePanels.

By reading the description of your page, this seems to be the case. The reason why the validators work on existing records is because all HTML elements are rendered at the same time as the initializing JavaScript attached to these elements. However, when creating a new record, the JavaScript is executed before the other two hidden fields are displayed, and hence the initializing JavaScript intended for these two fields are referring to null objects—that is if the hidden fields are not actually rendered in the HTML. When the user selects an item from the drop-down boxes, which fires the Async. PostBack, it is important to note that only the HTML within the UpdatePanels gets re-rendered, the rest of the page does not. Thus, the initializing JavaScript does not run again.

It may be worth your while to take a look at the ASP .NET AJAX Async. PostBack Page-Cycle listed here:http://ajax.asp.net/docs/overview/PageRequestManagerOverview.aspx. I found it to be very helpful. Also, take a look at how Partial Page Loading works to get a better understanding of the UpdatePanel idiom:http://ajax.asp.net/docs/overview/PartialPageRenderingOverview.aspx.

Hope this helps.


delta1186:

Like I said all the validation controls work when a user edits an existing record because all the fields are shown when the page loads. How do you get the client-side code updated after the async-postback?

Sorry, I did not read this question. I would take a look at the link I posted to the PageRequestManager (http://ajax.asp.net/docs/overview/PageRequestManagerOverview.aspx) which, again, explains the life cycle of async. Postbacks but also how the PageRequestManager object, provided by AJAX ASP .NET, can be used to execute custom JavaScript during the life-cycle events. What I did to re-hook my JavaScript with the new HTML elements in my UpdatePanels is I wrote a function that basically uses the JavaScript getElementById function to reassign the HTML element to the JavaScript variable.

My situation was a bit different than yours in which I wrote all the JavaScript for the functionality of my custom user control, so it was easy for me to "re-hook" things together. However, in your case, you're using ASP .NET server controls with ASP .NET AJAX, so I am not too sure how HTML elements are actually hooked into the JavaScript. The PageRequestManager is a good start though. Maybe do a bit of digging around on the MSDN websites and ASP .NET AJAX documentation for an initialize function, and reexecute that function during the endRequest event (http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerEndRequestEvent.aspx) of the async. postback page cycle.

Good luck. Let me know how it goes.


Hi,

The validators are not compatible with UpdatePanel, please try to usethis version instead.

Hope this helps.

Question on DynamicUpdate properties...

When using this feature - my understanding is that the principle around it is to use a web service.

Say for a popup form modal or otherwise... one was to use it...

how do you go about setting security principles and otherwise preventing someone that shouldn't have access to it beyond the mere fact you can authenticate prior to...my concern is security using this feature...are there any examples to look at that do not use the profile services that guards against someone using a tool like fiddler from manipulating and querying or otherwise being able to submit when using Atlas dynamic behaviors in this manner?

I'm not sure I understand what security issues you feel DynamicPopulate introduces (that aren't already present). Could you outline a scenario, perhaps?