Archive for April, 2006

27 Apr 2006

How to pass multiple values from child widow?

5 Comments ASP.NET

In my previous post I have provided couple of examples to explain how to show a dialog box using showModalDialog javascript function. With that, I also explain how to return value from child window to parent window using returnValue attribute. Now in this post, I will explain Javascript hack to return multiple values from child window. In this hack, we will return an class instance with multiple values already populated in child window.

Our core requirement here is that when user click on a button in parent form, application should open a child dialog box. In this child dialog box, user will enter some values and click on submit button to close the window. Javascript will thereafter populate all entered values in child window to the controls in parent page.

Read more

27 Apr 2006

Implementing dialog box in ASP.NET based web application

13 Comments ASP.NET

Note: This is rewrote of an article which I have published three years back in DotNetJunkies.com

Introduction
Using dialog box in any application is very important in order to provide close talks between user and application. These dialogs greatly enhance the usability of application.

Dialog box usually can be used to give some kind of feedback to user or to get some input from the user or even both which does require to display/change whole UI.

It was really a kid’s work to implement any dialog box in the window based application. Yes! It was very simple

Dim fChild As New frmChild
frmChild.Show vbModal

How easy it was??? But, how about opening the same kind dialog box in web based application? Oops! Its does require some hacking to open it, especially if you want to open a modal dialog box.

In the following article, we will see some of the important techniques of implementing dialog box in the web based application.

Read more

25 Apr 2006

How to set focus on ASP.NET control?

2 Comments ASP.NET

You can?t set focus on server control from code behind (as you have noticed, there is no focus method available for any server side control) and so your only alternative available is to use client side (read JavaScript) to set focus. Yes, you do can place concrete javascript implementation in each pages to set focus on controls. Or else you can create a generic method to accomplish this task.

Benefit of using server side mechanism of setting focus is that it reserves the cleanness of source code while managing focus on different controls on complex page.

Here is the approach:

First create a method in your utility (or any general static) class.

public void SetFocus(Control control)
{
if (control != null)
{
System.Text.StringBuilder script = new System.Text.StringBuilder();
script.Append("<script language='javascript'>");
script.Append("document.getElementById('" + control.ID + "').focus();");
script.Append("</script>");
Page.RegisterStartupScript("SetFocus", script.ToString());
}
}

And call this method from your page. Like below example will set focus on text box:
SetFocus(TextBox1);

Sameway, you can also set focus to other control as well. Like in following example, code will set focus to a button:
SetFocus(Button1);

That’s very easy!