AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 open ModalPopupExtender by select new(keyword) item in Dropdownlist
Posted by Sanjeev Gupta on  1/31/2008 3:37:35 AM Category: AJAX
Add to my favorites
Email to friend
i am using asp.net2.0 and ajax controlToolkit
problam is that when click first time in dropdown item new(keyword) then ModalPopupExtender is not open then second time click to new keyword then ModalPopupExtender is open so i want first click to open ModalPopupExtender.

Detail HTML code
//////////////////////////////////
<%@ Page Language="C#" MasterPageFile="~/Forms/Internal.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Forms_Default" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<table cellpadding="0" cellspacing="0" style="width: 748px; height: 176px">
<tr>
<td style="width: 100px; height: 176px;">
</td>
<td style="width: 100px; height: 176px;">
<table style="z-index: 100; left: 69px; width: 532px; top: 180px">
<tr>
<td align="left" style="width: 125px; height: 26px">
<strong><span style="color: #000066">Database Name</span></strong></td>
<td style="width: 7px; color: #000066; height: 26px">
<strong><span style="color: #000066">:</span></strong></td>
<td align="left" style="width: 239px; color: #000066; height: 26px">
<asp:TextBox ID="txtDatabase" runat="server" Style="z-index: 100; left: 305px; top: 178px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtDatabase"
Display="None" ErrorMessage="Please Enter Database Name"
Width="15px">*</asp:RequiredFieldValidator></td>
</tr>
<tr style="font-weight: bold; color: #000066">
<td align="left" style="width: 125px; height: 26px;">
User Name</td>
<td style="width: 7px; height: 26px;">
:</td>
<td align="left" style="width: 239px; height: 26px;">
<asp:TextBox ID="txtusername" runat="server" Style="z-index: 100; left: 295px; top: 207px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtusername"
Display="None" ErrorMessage="Please Enter User Name" Width="15px">*</asp:RequiredFieldValidator></td>
</tr>
<tr style="color: #000066">
<td align="left" style="width: 125px; height: 19px">
<strong>Password</strong></td>
<td style="font-weight: bold; width: 7px; height: 19px">
:</td>
<td align="left" style="font-weight: bold; width: 239px; height: 19px">
<asp:TextBox ID="txtpassword" runat="server" Style="z-index: 100; left: 296px; top: 228px"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtpassword"
Display="None" ErrorMessage="Please Enter Password" Width="15px">*</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="left" style="width: 125px; height: 19px">
Server Name</td>
<td style="width: 7px; height: 19px">
:</td>
<td align="left" style="width: 239px; height: 19px">
<asp:DropDownList ID="dboserverName" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
OnSelectedIndexChanged="dboserverName_SelectedIndexChanged" Style="z-index: 100;
left: 302px; top: 255px" OnTextChanged="dboserverName_TextChanged">
</asp:DropDownList>&nbsp;</td>
</tr>
<tr>
<td style="width: 125px; height: 21px">
</td>
<td style="width: 7px; height: 21px">
</td>
<td align="left" style="width: 239px; height: 21px">
<asp:Button ID="btnsubmit" runat="server" BackColor="#eff1ff" CssClass="submenubox"
Font-Bold="true" ForeColor="#000066" Height="22px" OnClick="btnsubmit_Click"
Style="z-index: 100; left: 296px; top: 233px" Text="Save" ValidationGroup="a"
Width="46px" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="dboserverName"
Display="None" ErrorMessage="Please Select Server Name" InitialValue="Select Database ...." Width="15px">*</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBox1"
Display="None" ErrorMessage="Please Enter Description" SetFocusOnError="True"
ValidationGroup="a">*</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="TextBox2"
Display="None" ErrorMessage="Please Enter server Name" ValidationGroup="a">*</asp:RequiredFieldValidator></td>
</tr>
</table>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" Width="181px" />
<asp:ValidationSummary ID="ValidationSummary2" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" ValidationGroup="a" />
&nbsp; &nbsp;
<asp:TextBox ID="TextBox3" runat="server" Visible="False" Width="78px"></asp:TextBox></td>
<td style="width: 100px; height: 176px;" >
<asp:Panel ID="Panel1" runat="server" BorderColor="Red" BorderStyle="Solid" BorderWidth="1px" BackColor="ButtonFace">
<table style="width: 197px">
<tr>
<td style="width: 81px; height: 26px;">
<asp:Label ID="Label1" runat="server" Text="Server Name" Width="86px"></asp:Label></td>
<td style="width: 100px; height: 26px;">
<asp:TextBox ID="TextBox2" runat="server" Width="100px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 81px; height: 26px;">
<asp:Label ID="Label2" runat="server" Text="Desc"></asp:Label></td>
<td style="width: 100px; height: 26px;">
<asp:TextBox ID="TextBox1" runat="server" Width="100px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 81px; height: 26px;">
</td>
<td style="width: 100px; height: 26px;">
<asp:Button ID="btnsubmit1" runat="server" Text="Save" OnClick="btnsubmit1_Click" ValidationGroup="a" />

<asp:Button ID="close1" runat="server" Text="close" CausesValidation="False" /></td>
</tr>
</table>
<cc1:MaskedEditExtender ID="ME1" runat="server" Mask="999.999.999.999"
MaskType="Number" TargetControlID="TextBox2">
</cc1:MaskedEditExtender>
<cc1:ModalPopupExtender ID="Mp1" runat="server"
PopupControlID="Panel1"
TargetControlID="TextBox3" BackgroundCssClass="modalBackground " CancelControlID="close1">
</cc1:ModalPopupExtender>
&nbsp;

</asp:Panel>
</td>
</tr>
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
&nbsp;</td>
<td style="width: 100px">
</td>
</tr>
</table>

</asp:Content>

///////////////////////////
.cs file

using System;
using System.Data;
using System.Data.SqlClient;
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 Forms_Default : System.Web.UI.Page
{
databaseClass db = new databaseClass();
string dbname;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Panel1.Visible = true;
drpbind();
}

//dboserverName.Attributes.Add("onclick", "var strReturn; strReturn=window.showModalDialog('Default2.aspx',null,'status:no; dialogWidth:100px; dialogHeight:100px; dialogHide:true; help:no;scroll:no') ");
fi();
}
void drpbind()
{
dboserverName.Items.Clear();
DataSet ds = new DataSet();
dbConnection dbcon = new dbConnection();
string connstring;
connstring = dbcon.ConString;
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = connstring;
myConnection.Open();
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM tblserver", myConnection);
ad.Fill(ds);
dboserverName.DataSource = ds;
dboserverName.Items.Insert(0, "Select Database ....");
dboserverName.Items.Insert(1, "New Item");
dboserverName.DataTextField = "vchIP";
dboserverName.DataValueField = "intServerId";
dboserverName.DataBind();
dboserverName.SelectedIndex = dboserverName.Items.IndexOf(dboserverName.Items.FindByText(Server));


}
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
Boolean authenticated;
Boolean returnvalue;
dbname = txtDatabase.Text.ToString();
authenticated = db.databasecheck(dbname);
returnvalue = authenticated;
if (returnvalue)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>window.alert('Database already exist');</script>");
}
else
{

string username;
string pwd;
string serverid;
dbname = txtDatabase.Text.ToString();
username = txtusername.Text.ToString();
pwd = txtpassword.Text.ToString();
serverid = dboserverName.SelectedValue.ToString();
db.databaseInsert(dbname, username, pwd, serverid);
// Response.Redirect("database.aspx");
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>window.alert('Database inserted');</script>");
}
}
}
protected void dboserverName_SelectedIndexChanged(object sender, EventArgs e)
{
//if (dboserverName.SelectedIndex == 1)
//{
// dboserverName.Attributes.Add("onclick", "var strReturn; strReturn=window.showModalDialog('Default2.aspx',null,'status:no; dialogWidth:100px; dialogHeight:100px; dialogHide:true; help:no;scroll:no') ");

//}


fi();

}
void fi()
{
if (dboserverName.SelectedIndex == 1)
{
Panel1.Visible = true;
Mp1.TargetControlID = "dboserverName";

Mp1.PopupControlID = "Panel1";
Mp1.BackgroundCssClass = "modalBackground";


}
else
Panel1.Visible = false;
}
private static string Server="";
string ServerIp;
string Descp;
ServerClass sc = new ServerClass();
protected void btnsubmit1_Click(object sender, EventArgs e)
{
int count = 0;
ServerIp = TextBox2.Text;
string[] items = ServerIp.Split('.');

int i = Convert.ToInt32(items[0]);
int j = Convert.ToInt32(items[1]);
int k = Convert.ToInt32(items[2]);
int l = Convert.ToInt32(items[3]);
if (i == 0)
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>window.alert('IPAddress Is Invalid');</script>");
else
{
if (j == 0)
count++;
if (k == 0)
count++;
if (l == 0)
count++;
if (count >= 2)
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>window.alert('IPAddress Is Invalid');</script>");
else
{
string Ip = Convert.ToString(i) + "." + Convert.ToString(j) + "." + Convert.ToString(k) + "." + Convert.ToString(l);
Boolean authenticated;
Boolean returnvalue;
authenticated = sc.Servercheck(Ip);
returnvalue = authenticated;
if (returnvalue)
{
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>window.alert('IPAddress already exist');</script>");
}
else
{
Server = Ip;
Descp = TextBox1.Text.ToString();
sc.ServerInsert(Ip, Descp);
Panel1.Visible = false;
drpbind();
}
}
}
}
}

Post Your Reply Post New Question

 Viewer's Reply
Openning a ModalPopup From DownDown List control
Answered By Moderator1 on 6/22/2010 1:31:19 AM
Hi,

You can do it easily through server-side code as below,

protected void dboserverName_SelectedIndexChanged(object sender, EventArgs e)
{
if (dboserverName.SelectedValue == "New Item")
Mp1.Show();
}
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Washington Technology
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks - Free 158 Page Preview