Welcome Guest Search | Active Topics | Sign In | Register

dialog question Options
Eshop-Xperts
Posted: Tuesday, June 19, 2007 4:38:24 PM
Rank: Member
Groups: Member

Joined: 6/3/2007
Posts: 11
HI, could I get some sample code on how to use the dialog in a conditional statement.

ie.. if I have a text box and I want to show validation details (ie.. you need to enter your ebay id etc)..

like the following:

if(txtEbay.text.length==0)
... show the dialog here not modal
else if (txtEmail.text.length==0)
.. show the dialog as model
else
.. do other processing and dont show the dialg

eo_support
Posted: Tuesday, June 19, 2007 6:50:02 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
Thanks for posting your question here. You can do it this way:

Code: JavaScript
//Get the dialog object
var dialog = eo_GetObject("your_dialog_id");
if(txtEbay.text.length==0)
    dialog.show(false);    //display the dialog not modal
else if (txtEmail.text.length==0)
    dialog.show(true);     //display the dialog modal
else
.. do other processing and dont show the dialg


Thanks
Eshop-Xperts
Posted: Wednesday, June 20, 2007 2:14:59 PM
Rank: Member
Groups: Member

Joined: 6/3/2007
Posts: 11
How do I initiate the javascript from c# though?
eo_support
Posted: Wednesday, June 20, 2007 2:22:40 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
No. You can not. C# code executes on the server side and Javascript code executes on the client side, so you can't really "initiate" one from another. However, it's very common to have the server side C# code to generates Javascript code on the server side and then passes it to the client side, at which point the client browser runs it. Many server controls does this, but I doubt whether this is your scenario.

Please reply with a bit more information about your scenario and then we will make suggestions based on your scenario.

Eshop-Xperts
Posted: Wednesday, June 20, 2007 3:01:29 PM
Rank: Member
Groups: Member

Joined: 6/3/2007
Posts: 11
Im validating data to put into a database and what to initiate the dialog to display any validation errors to the user.

ie.

the user adds a ebay username and other information andin the code we use regex to validate the fields and formats. If all is ok we write the data to the database. If we ahve validation errors we want to display the dialog box with the list of the errors to the user.

eo_support
Posted: Wednesday, June 20, 2007 3:28:25 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
OK...there are two ways to this. I'll try to explain both and please feel free to reply if you have any questions regarding either of them.

The easiest way is to do it on client side. Say you have a text box and a "Submit" button:

Code: HTML/ASPX
<asp:TextBox runat="server" id="userInput" />
<asp:Button runat="server" id="submitButton" Text="Submit" />


You would attach a onclick handler to the button, let's call it "verifyInput" and. Inside that function you can verify the user's input and if it is invalid, you can:
1. Display a dialog box;
2. Returns false to cancel the submit;
Both steps are important.

Code: JavaScript
function verifyInput()
{
   var dialog = eo_GetObject("your_dialog_id");
   var textBox = document.getElementById("userInput");

   //check whether the text box is empty
   if (textBox.value.length == 0)
   {
       //Display the dialog
       dialog.show(true); 

      //Returns false to cancel the submt
       return false;
   }
}


Code: HTML/ASPX
<asp:Button runat="server" id="submitButton" 
    Text="Submit" onclick="return verifyInput()" />


A second way is to do everything on the server side. This way you would need to use a CallbackPanel control. It will be something like this:

Code: HTML/ASPX
<eo:CallbackPanel runat="server" 
    id="CallbackPanel1" Triggers="{ID:submitButton;Parameter:}">
    <eo:Dialog runat="server" id="Dialog1">
     ...dialog stuff...
    </eo:Dialog>
</eo:CallbackPanel>


At here the submitButton is set to trigger the Callback (through Triggers property). You will then handle submitButton_Click event and verify user's input:

Code: C#
private void submitButton_Click(object sender, EventArgs e)
{
    if (userInput.Text.Length == 0)
        Dialog1.InitialState = DialogState.Visible;
    else
    {
        Dialog1.InitialState = DialogState.Hidden;

        //user input is OK. continue to write it to DB
    }
}


The key of this second method is the dialog's InitialState property.
Eshop-Xperts
Posted: Thursday, June 21, 2007 2:16:46 PM
Rank: Member
Groups: Member

Joined: 6/3/2007
Posts: 11
Hi, that works excellent.. one other question though... If i edit the content template of the dialog and add label or text boxes that I wanted to fill with data, how do I set these? I cannot seem to see the textbox or label objects in code..
eo_support
Posted: Thursday, June 21, 2007 5:51:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,098
Hi,

You will need to do:

Code: C#
Label label = (Label)Dialgo1.ContentContainer.FindControl("Label1");
label.Text = "something";


Thanks
Eshop-Xperts
Posted: Friday, June 22, 2007 1:33:14 AM
Rank: Member
Groups: Member

Joined: 6/3/2007
Posts: 11
getting an error on the 'ContentTemplate'. It doesnt show up as a property of the control.

Error 1 'EO.Web.Dialog' does not contain a definition for 'ContentContainer'

Eshop-Xperts
Posted: Friday, June 22, 2007 3:20:28 AM
Rank: Member
Groups: Member

Joined: 6/3/2007
Posts: 11
Aha.. problem solved if I remove the ContentContainer.

Label label = (Label)Dialog1.FindControl("Label1");



You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.