I have been working on a project and facing an error as i have two textbox and a dropdown when i fill one of the textbox on its selecting_indexchanged the dropdown get filled,what is happening is when i click on reset button to reset the dropdown a textboxes to be blank and dropowns index value to 0,its shows as error as
"dropdown has a SelectedIndex which is invalid because it does not exist in the list of items.
Parameter name: value "
<td class="style4">
<asp:Label ID="lbl_bookname" runat="server" Text="Book Name"
ForeColor="Black"></asp:Label>
</td>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txt_bookname" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="getbookname">
</asp:AutoCompleteExtender>
<td class="style4">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txt_bookname" runat="server" ValidationGroup="a" OnTextChanged="editiondrpfill_TextChanged" AutoPostBack="true"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" TargetControlID="txt_bookname" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000" ServiceMethod="getbookname">
</asp:AutoCompleteExtender>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ErrorMessage="*" ForeColor="Red" ControlToValidate="txt_bookname"
ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
<td class="style4">
<asp:Label ID="lbl_condition" runat="server" ForeColor="Black" Text="Condition"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="txt_condition" runat="server" BackColor="White"
ReadOnly="True" Width="120px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
ControlToValidate="txt_condition" ErrorMessage="*" ForeColor="Red"
ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="lbl_edition" runat="server" ForeColor="Black" Text="Edition"></asp:Label>
</td>
<td class="style4">
<asp:DropDownList ID="drp_edition" runat="server" ValidationGroup="a"
Width="120px" onselectedindexchanged="drp_edition_SelectedIndexChanged"
AutoPostBack="true" TabIndex="0">
</asp:DropDownList>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="drp_edition" ErrorMessage="*" ForeColor="Red"
ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
CS Code for filling of dropdown
protected void editiondrpfill_TextChanged(object sender, EventArgs e)
{
sql = "select bt.booktwo_id,bt.edition,b.bookname from library_book b , library_booktwo bt where bookname ='" + txt_bookname.Text+ "' and bt.book_id=b.book_id";
ds = obj.openDataset(sql, Session["SCHOOLCODE"].ToString());
drp_edition.Items.Clear();
ListItem li = new ListItem();
li.Text = "Select the value";
li.Value = "0";
drp_edition.Items.Add(li);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
li = new ListItem();
li.Text= ds.Tables[0].Rows[i]["edition"].ToString();
li.Value = ds.Tables[0].Rows[i]["booktwo_id"].ToString();
drp_edition.Items.Add(li);
}
}
cs code for reset button event
protected void btn_reset_Click(object sender, EventArgs e)
{
txt_bookname.Text = "";
txt_condition.Text = "";
txt_member_id.Text = "";
txt_nameofstudent.Text = "";
txt_quantity.Text = "";
drp_edition.SelectedIndex = 0;
drp_isbn.SelectedIndex = 0;
}
Do one thing on your aspx.cs page add a ListItem to dropdown with value 0 like
<asp:DropDownList ID="drp_edition" runat="server" ValidationGroup="a"
Width="120px" onselectedindexchanged="drp_edition_SelectedIndexChanged"
AutoPostBack="true" TabIndex="0">
<asp:ListItem Value="0" Text="Select" ></asp:ListItem>
</asp:DropDownList>
It will solve your problem.
Hope it works.
Place the default list item for the dropdown "drp_edition".
Since,you are assigned the selectedindex=0 in reset fn.
There should some list item in this case.
<td class="style4">
<asp:DropDownList ID="drp_edition" runat="server" ValidationGroup="a" Width="120px"
onselectedindexchanged="drp_edition_SelectedIndexChanged" AutoPostBack="true" TabIndex="0">
<asp:ListItem Text="--Select--" Value="0" />
</asp:DropDownList>
</td>
<td class="style4">
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="drp_edition" ErrorMessage="*" ForeColor="Red" InitialValue="0"
ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
Related
I am trying to get validation where i can check what user inter in TextBox is valid PartNumber which is in my database.
My asp page looks like . and code behind is
<table width="50%" border="1" align="center">
<tr>
<td width="30%" class="style1">
<b>Part Number :</b>
</td>
<td class="style1">
<asp:TextBox ID="lpartno" runat="server" Width="300px"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="GetCompletionListPartno" MinimumPrefixLength="1"
CompletionInterval="1" EnableCaching="false" TargetControlID="lpartno"
ID="AutoCompleteExtender2" runat="server" FirstRowSelected="false">
</cc1:AutoCompleteExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="lpartno" TargetControlID="lpartno" ErrorMessage="PartNumber is Required" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="30%">
<b>Reveived Date :</b>
</td>
<td>
<asp:TextBox ID="lReceivedDate" runat="server" CausesValidation="True" ></asp:TextBox>
<cc1:CalendarExtender ID="lReceivedDate_CalendarExtender" runat="server" Enabled="True"
TargetControlID="lReceivedDate">
</cc1:CalendarExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="lReceivedDate" TargetControlID="lReceivedDate" ErrorMessage="Reveived Date is Required" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td width="30%">
<b>PO Number :</b>
</td>
<td>
<asp:TextBox ID="lPONo" runat="server" Width="300px"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="GetCompletionListPONo" MinimumPrefixLength="1"
CompletionInterval="1" EnableCaching="false" TargetControlID="lPONo"
ID="AutoCompleteExtender3" runat="server" FirstRowSelected="false">
</cc1:AutoCompleteExtender>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="lPONo" TargetControlID="lPONo" ErrorMessage="PO Number is Required" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
I would like to have validation we i can check the Part number user is entering is in my database table. if not it should so some error message.
Please advice how i will achieve this !!
Thanks in advance !!
This is the way I solved this problem
protected void CustomValidator2_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = false;
string StaffID = lpartno.Text;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["eFoxNetConnectionString"].ConnectionString;
SqlDataAdapter da = new SqlDataAdapter("select distinct PartNo from dbo.FTX_SAPPO sp with (nolock) where PartNo=#ID",conn);
da.SelectCommand.Parameters.Add("#ID", SqlDbType.VarChar, 120);
da.SelectCommand.Parameters["#ID"].Value = StaffID;
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
args.IsValid = true;
}
I have 3 textBoxes in a page .One of the textBox takes the new Password from the user and according to the password entered by the user , a Label displays Password strength message.But after the message displayed by the Label , the textBox text is cleared.is there a way to retain the text? I have enabled the autopostback for the textbox since i need to use the Comparevalidator for it.
Here is the code snippet-
protected void NewPassEntered(object sender, EventArgs e)
{
if (txtPassword.Text.Length < 4)
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.OrangeRed;
lblPassStr.Text = "Password should have more than four characters";
txtPassword.Text = "";
}
else if ((txtPassword.Text.Length > 4) && (txtPassword.Text.Length < 6) && (txtPassword.Text.Contains("#")))
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.Green;
lblPassStr.Text = "Password Strength:Medium";
}
else if ((txtPassword.Text.Length > 4) && (txtPassword.Text.Length < 6))
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.Yellow;
lblPassStr.Text = "Password Strength:Weak";
}
else if ((txtPassword.Text.Length > 6) && (txtPassword.Text.Contains("#")))
{
lblPassStr.Visible = Visible;
lblPassStr.BackColor = System.Drawing.Color.Blue;
lblPassStr.Text = "Password Strength:Strong";
}
}
}
Is there a way to check multiple special characters efficiently?
The aspx code looks like this-:
<div style="width:400px; height:250px;border-color:GoldenRod ;border-style:solid;border-width:thin;padding:20px 50px 50px 20px; position:relative; margin:100px 100px; margin-left:344px">
<table border="0" align="center" cellpadding="0" cellspacing="0" width="350" >
<tr><td> <br /></td></tr>
<tr>
<td style="width:200px">
<span class="labeltxt"> Old Password: </span>
<br /></td></tr><tr> <td style="width:200px"> <asp:TextBox ID="txtoldpass"
runat="server" CssClass="text" TextMode="Password" Width="300px"
Height="25" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*Enter the old password" ControlToValidate="txtoldpass" Text="*" ForeColor="Red" InitialValue="">
</asp:RequiredFieldValidator><br />
</td>
</tr>
<tr>
<td><br /></td>
</tr>
<tr>
<td style="width:200px">
<span>New Password: </span>
<br /></td></tr><tr>
<td style="width:200px">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="text"
Width="300px" Height="25"
ontextchanged="NewPassEntered"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Font-Italic="true" ErrorMessage="**Enter the new password!" ControlToValidate="txtPassword" Text="**" ForeColor="Red" InitialValue="">
</asp:RequiredFieldValidator>
<br /></td>
</tr>
<tr>
<td><br />
<asp:Label ID="lblPassStr" runat="server" Text="Label" Visible="False"></asp:Label></td>
</tr>
<tr>
<td style="width:200px">
<span>Confirm Password:</span>
<br /> </td></tr>
<tr>
<td style="width:200px"> <asp:TextBox ID="txtPassword1" runat="server"
TextMode="Password" CssClass="text" Width="300px" Height="25"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="***Enter the new password again!" ControlToValidate="txtPassword1" Text="***" ForeColor="Red" InitialValue="">
</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ErrorMessage="Passwords do not Match!" ControlToCompare="txtPassword"
ControlToValidate="txtPassword1"></asp:CompareValidator>
<br /> </td>
</tr>
<tr>
<td><br /><br /></td>
</tr>
<tr>
<td>
<asp:Button runat="server" ID="btnLogin" Text="Save" Height="25px"
Width="76px" CssClass="btn" BackColor="Goldenrod" onclick="btnLogin_Click"></asp:Button><asp:HyperLink ID="HyperLink1" runat="server">Cancel</asp:HyperLink>
</td>
</tr>
</table>
</div>
<asp:ValidationSummary ID="ValidationSummary1" Font-Italic="true" font-size="Small" forecolor="Black" runat="server" />
Don't postback the whole page for just setting a Password strength label. Use Javascript for this. There will be 2 benefits of using javascript here.
1) The page will not be postback (By Postback whole page will be refreshed and just because of a single field whole page postback is not a good practice)
2) No need to maintain the state of textbox as there is no postback.
What about using EnableViewState =false ?
<asp:TextBox ID="txtoldpass" runat="server" EnableViewState ="False" CssClass="text" TextMode="Password"
Width="300px" Height="25" ></asp:TextBox>
How to access LoginView1 control inside Multiview1, View2?
I have a some textbox and dropdownlist in loggedIn template of View 2 within Multiview, I need to get the control and bind with text from database.
I had try:
((TextBox)this.LoginView1.FindControl("custEmail")).Text = dr.GetValue(1).ToString();
((TextBox)LoginView1.FindControl("custEmail")).Text = dr.GetValue(1).ToString();
((TextBox)LoginView1.FindControl("custEmail")).Text = "xxxx";
return "Object reference not set to an instance of an object."
Markup Code
<asp:View ID="View2" runat="server" OnActivate="login_Click">
<asp:Label ID="tprice" runat="server" /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:LoginView ID="LoginView1" runat="server" ViewStateMode="Disabled">
<AnonymousTemplate>
Please login to continue.<br />
<asp:Login ID="Login1" runat="server" ViewStateMode="Disabled" RenderOuterTable="false">
<LayoutTemplate>
<fieldset>
<legend>Log in Form</legend>
<ul>
<li>
<asp:Label ID="Label2" runat="server" AssociatedControlID="UserName">User name</asp:Label>
<asp:TextBox runat="server" ID="UserName" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="UserName"
CssClass="field-validation-error" ErrorMessage="The user name field is required." />
</li>
<li>
<asp:Label ID="Label4" runat="server" AssociatedControlID="Password">Password</asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="Password"
CssClass="field-validation-error" ErrorMessage="The password field is required." />
</li>
</ul>
<asp:Button ID="login" runat="server" CommandName="Login" OnCommand="login_Click"
Text="Log in"
CssClass="btn btn-info" />
</fieldset>
<asp:Label runat="server" ID="FailureText" class="validation-summary-errors" />
</LayoutTemplate>
</asp:Login>
or
<a id="registerLink" runat="server" href="~/Account/Register">Register</a>
to continue
</AnonymousTemplate>
<LoggedInTemplate>
<table class="custable">
<tr>
<td>
<asp:Label ID="Label5" AssociatedControlID="title" runat="server" Text="Title : " />
</td>
<td>
<asp:DropDownList ID="title" runat="server">
<asp:ListItem Value="0">Select One...</asp:ListItem>
<asp:ListItem Value="Mr">Mr</asp:ListItem>
<asp:ListItem Value="Mrs">Mrs</asp:ListItem>
<asp:ListItem Value="Miss">Miss</asp:ListItem>
<asp:ListItem Value="Ms">Ms</asp:ListItem>
<asp:ListItem Value="Doctor">Doctor</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="title" ValueToCompare="0" Operator="NotEqual"
Text="Please select the title." CssClass="field-validation-error"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" AssociatedControlID="name" runat="server" Text="Full Name As Per IC : " />
</td>
<td>
<asp:TextBox ID="name" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="name"
CssClass="field-validation-error" Text="*Required"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label7" AssociatedControlID="custEmail" runat="server" Text="Email : " />
</td>
<td>
<asp:TextBox ID="custEmail" runat="server" TextMode="Email" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="custEmail"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label8" AssociatedControlID="email2" runat="server" Text="Confirm Email : " />
</td>
<td>
<asp:TextBox ID="email2" runat="server" TextMode="Email" />
</td>
<td>
<asp:CompareValidator ID="CompareValidator2" ControlToCompare="email2" ControlToValidate="custEmail"
runat="server"
Operator="Equal" Type="String" Text="Please enter same Email." CssClass="field-validation-error"
ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label9" AssociatedControlID="icPassport" runat="server" Text="IC / Passport : " />
</td>
<td>
<asp:TextBox ID="icPassport" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="icPassport"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label10" AssociatedControlID="mobile" runat="server" Text="Mobile : " />
</td>
<td>
<asp:TextBox ID="mobile" runat="server" placeholder="60123456789" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="mobile"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" /><br />
<asp:CompareValidator ID="CompareValidator3" runat="server" ControlToValidate="mobile"
Operator="DataTypeCheck" Type="Double" ErrorMessage="Mobile number must be integer."
CssClass="field-validation-error" ValidationGroup="vg1" Display="None" /><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="mobile"
ErrorMessage="Mobile Number must within 10 to 18 digits." ValidationExpression="^\d{10,18}$"
CssClass="field-validation-error" ValidationGroup="vg1" Display="None" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label11" AssociatedControlID="street" runat="server" Text="Street : " />
</td>
<td>
<asp:TextBox ID="street" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="street"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label12" AssociatedControlID="townstate" runat="server" Text="Town / State : " />
</td>
<td>
<asp:TextBox ID="townstate" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="townstate"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label13" AssociatedControlID="country" runat="server" Text="Country : " />
</td>
<td>
<asp:DropDownList ID="country" runat="server" />
</td>
<td>
<asp:CompareValidator ID="CompareValidator4" runat="server"
ControlToValidate="country" ValueToCompare="Select One..." Type="String" Operator="NotEqual"
Text="*" CssClass="field-validation-error"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label14" AssociatedControlID="postalcode" runat="server" Text="Postal Code : " />
</td>
<td>
<asp:TextBox ID="postalcode" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="postalcode"
CssClass="field-validation-error" Text="*"
SetFocusOnError="true" ValidationGroup="vg1" /><br />
<asp:CompareValidator ID="CompareValidator5" runat="server" ControlToValidate="postalcode"
Type="Integer" Operator="DataTypeCheck" ErrorMessage="Postal Code must be integer."
CssClass="field-validation-error" ValidationGroup="vg1" Display="none" /><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="postalcode"
ErrorMessage="Postal Code, 5 or 9 Digits." ValidationExpression="\d{5}?(\d{4})?$"
CssClass="field-validation-error" ValidationGroup="vg1" Display="None" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label15" AssociatedControlID="yearOfBirth" runat="server" Text="Year Of Birth : " />
</td>
<td>
<asp:DropDownList ID="yearOfBirth" runat="server">
<asp:ListItem Value="0">Year</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:CompareValidator ID="CompareValidator6" runat="server"
ControlToValidate="yearOfBirth" ValueToCompare="0" Operator="NotEqual"
Text="*" CssClass="field-validation-error"
SetFocusOnError="true" ValidationGroup="vg1" />
</td>
</tr>
</table>
</LoggedInTemplate>
</asp:LoginView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" Text="Next" CommandName="NextView" runat="server" />
</asp:View>
C# Code Behind
protected void login_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
if (User.Identity.IsAuthenticated)
{
string userId = (Membership.GetUser().ProviderUserKey).ToString();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand();
string selectcmd = "select Email from Memberships where userID='" + userId + "'";
string selectcmd2 = "select custEmail, title, name, icPassport, mobile, street, townstate, postalcode, townstate, yearOfBirth from custInfo where userID='" + userId + "'";
SqlDataReader dr;
cmd = new SqlCommand(selectcmd2, con);
con.Open();
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
((TextBox)this.LoginView1.FindControl("custEmail")).Text = dr.GetValue(1).ToString();
((DropDownList)LoginView1.FindControl("title")).SelectedValue = dr.GetValue(2).ToString();
((TextBox)LoginView1.FindControl("name")).Text = dr.GetValue(3).ToString();
((TextBox)LoginView1.FindControl("icPassport")).Text = dr.GetValue(4).ToString();
((TextBox)LoginView1.FindControl("mobile")).Text = dr.GetValue(5).ToString();
((TextBox)LoginView1.FindControl("street")).Text = dr.GetValue(6).ToString();
((DropDownList)LoginView1.FindControl("townstate")).SelectedValue = dr.GetValue(7).ToString();
((TextBox)LoginView1.FindControl("postalcode")).Text = dr.GetValue(8).ToString().Trim();
((TextBox)LoginView1.FindControl("townstate")).Text = dr.GetValue(9).ToString();
((DropDownList)LoginView1.FindControl("yearOfBirth")).SelectedValue = dr.GetValue(10).ToString();
}
dr.Close();
con.Close();
}
else
{
dr.Close();
cmd = new SqlCommand(selectcmd, con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
(this.LoginView1.FindControl("custEmail") as TextBox).Text = dr.GetValue(0).ToString();
}
dr.Close();
con.Close();
}
}
}
Keep in mind that FindControl searches only the current level If you want to search in the branches (inside a MultiView, Panel, PlaceHolder, etc.) as well then you have to use some kind of recursive search.
First find the control in multiview control and by using MultiView.FindControl Method and then access the child controls in that found control
some sample posts
http://www.codeproject.com/Articles/13836/Find-child-controls-inside-a-MultiView-control-in
i got a task for creating leave application for the employees.. it contains 3 tabs one with apply leave which has
type for leave
description
begin date
end date
number of days
those begin and end date contains calendar extenders and once i select both dates , cursor should point on number of days textbox and it should calculate the total number of days leave will be taken... please help me sort this out..
i have tried this
cs
protected void BtnApply_Click(object sender, EventArgs e)
{
MTMSDTO objc = new MTMSDTO();
int Flag = 0;
LblLogdInUser.Text = Session["EmpName"].ToString();
objc.LoggedInUser = LblLogdInUser.Text;
objc.TypeofLeave = DrpTypeofLeave.SelectedItem.Text;
string date;
date = Convert.ToDateTime(TxtBeginDate.Text).ToString("dd/MM/yyyy");
DateTime dt = new DateTime();
dt = Convert.ToDateTime(date);
objc.BeginDate = dt;
objc.EndDate = Convert.ToDateTime(TxtEndDate.Text);
objc.Description = TxtDescription.Text;
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
//objc.EmpName = LblLogdInUser.Text;
int X = obj.InsertLeave(objc);
{
if (X >= 0)
{
Flag = 1;
}
else
{
Flag = 0;
}
}
if (Flag == 1)
{
LblSuccess.Visible = true;
LblSuccess.Text = "Data Added Successfully";
DrpTypeofLeave.ClearSelection();
TxtBeginDate.Text = "";
TxtEndDate.Text = "";
TxtDescription.Text = "";
TxtNumofDays.Text = "";
}
else
{
LblErr.Visible = true;
LblErr.Text = "Failed To Add Data!!!";
}
}
protected void TxtNumofDays_TextChanged1(object sender, EventArgs e)
{
MTMSDTO objc = new MTMSDTO();
TxtNumofDays.Text = Session["NumofDays"].ToString();
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
}
protected void TxtEndDate_TextChanged(object sender, EventArgs e)
{
DateTime BeginDate = Convert.ToDateTime(TxtBeginDate.Text);
DateTime EndDate = Convert.ToDateTime(TxtEndDate.Text);
TimeSpan diff = EndDate.Subtract(BeginDate);
TxtNumofDays.Text = diff.Days.ToString();
TxtNumofDays.Focus();
}
aspx
<asp:Panel ID="Panel1" runat="server" Height="567px" Width="858px">
<table style="width:100%; height: 587px;">
<tr>
<td class="style50">
</td>
<td class="style51">
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0"
Height="550px" Width="833px">
<asp:TabPanel ID="TabLAP" runat="server" HeaderText="Leave Application">
<HeaderTemplate>
<span class="style40"><strong>Leave Application</strong></span>
</HeaderTemplate>
<ContentTemplate>
<table style="width:101%; height: 505px; margin-left: 0px;">
<tr>
<td class="style160" style="font-weight: 700;">
</td>
<td class="style161" style="font-weight: 700; ">
<asp:Label ID="LblLogdInUser" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="23px" Visible="False" Width="123px"></asp:Label>
<asp:RoundedCornersExtender ID="LblLogdInUser_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="LblLogdInUser"></asp:RoundedCornersExtender>
</td>
<td class="style162" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
Type Of Leave:</td>
<td class="style156">
<asp:DropDownList ID="DrpTypeofLeave" runat="server"
AppendDataBoundItems="True" BorderColor="#0061C1" BorderWidth="1px"
Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small" ForeColor="#0061C1"
Height="29px" onselectedindexchanged="DrpTypeofLeave_SelectedIndexChanged1"
style="text-align: left" Width="123px"><asp:ListItem Selected="True" Value="0">Please Select</asp:ListItem><asp:ListItem
Value="1">Sick Leave</asp:ListItem><asp:ListItem Value="2">Casual Leave</asp:ListItem><asp:ListItem
Value="3">Earned Leave</asp:ListItem>
</asp:DropDownList>
<asp:RoundedCornersExtender ID="DrpTypeofLeave_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="DrpTypeofLeave"></asp:RoundedCornersExtender>
</td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style146" style="font-weight: 700; ">
Description:</td>
<td class="style154" style="font-weight: 700; ">
<asp:TextBox ID="TxtDescription" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" style="text-align: left" TextMode="MultiLine"
Width="103px"></asp:TextBox>
<asp:RoundedCornersExtender ID="TxtDescription_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtDescription"></asp:RoundedCornersExtender>
</td>
<td class="style144" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
Begin Date:</td>
<td class="style156" style="font-weight: 700; ">
<asp:TextBox ID="TxtBeginDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" style="text-align: left" Width="73px"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtBeginDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton1"
PopupPosition="Right" TargetControlID="TxtBeginDate"
TodaysDateFormat="dd/MM/yyyy"></asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtBeginDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtBeginDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkBeginDate" runat="server"
ControlToValidate="TxtBeginDate" Display="Dynamic"
ErrorMessage="You must supply a valid start date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" /><td class="style141"
style="font-weight: 700; ">
</td>
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
End Date:</td>
<td class="style156" style="font-weight: 700; ">
<asp:TextBox ID="TxtEndDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" ontextchanged="TxtEndDate_TextChanged"
style="text-align: left" Width="73px" AutoPostBack ="true"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtEndDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton2"
PopupPosition="Right" TargetControlID="TxtEndDate"
TodaysDateFormat="dd/MM/yyyy"></asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtEndDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtEndDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkEndDate" runat="server"
ControlToValidate="TxtEndDate" Display="Dynamic"
ErrorMessage="You must supply a valid end date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" /><br />
<asp:CompareValidator ID="cmpBeginAndEndDates" runat="server"
ControlToCompare="TxtBeginDate" ControlToValidate="TxtEndDate"
Display="Dynamic" ErrorMessage="The end date must be after the start date"
ForeColor="Red" Operator="GreaterThan" /></td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
Number of Days:</td>
<td class="style156" style="font-weight: 700; ">
<asp:TextBox ID="TxtNumofDays" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" ontextchanged="TxtNumofDays_TextChanged1"
style="text-align: left" Width="73px"></asp:TextBox>
<asp:RoundedCornersExtender ID="TxtNumofDays_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtNumofDays"></asp:RoundedCornersExtender>
</td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style164" style="font-weight: 700; ">
<br />
<asp:Label ID="LblSuccess" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="X-Small" ForeColor="#009933" Height="14px" style="text-align: right"
Visible="False"></asp:Label>
<br />
<asp:Label ID="LblErr" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="X-Small" ForeColor="#CC0000" Height="14px" Visible="False"></asp:Label>
</td>
<td class="style163" style="font-weight: 700; ">
<asp:Button ID="BtnApply" runat="server" BackColor="White"
BorderColor="#0061C1" BorderWidth="1px" CssClass="ButtonClass" Font-Bold="True"
Font-Names="Verdana" Font-Size="Small" ForeColor="#0061C1" Height="21px"
OnClick="BtnApply_Click" Text="Apply" Width="65px" />
<asp:RoundedCornersExtender ID="BtnApply_RoundedCornersExtender1"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="BtnApply"></asp:RoundedCornersExtender>
<asp:Button ID="BtnCancel" runat="server" BackColor="White"
BorderColor="#0061C1" BorderWidth="1px" CssClass="ButtonClass" Font-Bold="True"
Font-Names="Verdana" Font-Size="Small" ForeColor="#0061C1" Height="21px"
OnClick="BtnCancel_Click" Text="Cancel" Width="65px" />
<asp:RoundedCornersExtender ID="BtnCancel_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="BtnCancel"></asp:RoundedCornersExtender>
</td>
<td class="style165" style="font-weight: 700; ">
</td>
</tr>
<tr>
<td class="style159" style="font-weight: 700; ">
</td>
<td class="style156" style="font-weight: 700; ">
</td>
<td class="style141" style="font-weight: 700; ">
</td>
</tr>
</table>
</ContentTemplate>
</asp:TabPanel>
</asp:Panel>
I'm getting the number of days value in my database but its not showing in the textbox and cursor is not pointing too to the textbox of number of days wen i run the project..
I think you are taking the hard way out there is a much easier way of implementing what you are trying to do in ASP.net. First it would require the use of jQuery UI (date-picker). I came up with a pure JavaScript and HTML5 solution to your problem. I think you are going a bit over board with the post back of the data just so you can get the date out of it.
Note: I am not doing any validation nor have I made this specific towards your application.
Here is my solution:
CSS style, just to make things okay looking ;)
<!-- link to the jQuery UI CSS -->
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<style>
#employee_form {
width: 350px;
background: #f0e68c;
padding: .2em;
}
li {
list-style: none;
font-weight: bold;
}
li input {
float: right;
}
</style>
aspx page
<form id="form1" runat="server">
<div id="employee_form">
<ul>
<li>
<p>
<asp:Label ID="Label1" runat="server" Text="Type of leave"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label6" runat="server" Text="Description"></asp:Label>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label2" runat="server" Text="Begin Date"></asp:Label>
<asp:TextBox ID="beginDate" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label3" runat="server" Text="End Date"></asp:Label>
<asp:TextBox ID="endDate" runat="server"></asp:TextBox>
</p>
</li>
<li>
<p>
<asp:Label ID="Label4" runat="server" Text="Number of Days"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</p>
</li>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
</ul>
</div>
</form>
JavaScript
<!-- link to the latest jquery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<!-- link to the jQuery UI -->
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
(function () {
$('.date').datepicker();
var resultDate = "";
$('.date').on('change', function () {
var beginDate = $('#beginDate').val();
var endDate = $("#endDate").val();
if (beginDate != "" && endDate != "") {
beginDate = new Date(beginDate);
endDate = new Date(endDate);
resultDate = endDate.getDate() - beginDate.getDate();
}
$("#days").val(resultDate + " ");
});
})();
</script>
cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _Web_StackoverFlow_Question_Test_Code
{
public partial class EmployeeLeaveForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// Submit the data to the database
}
}
}
End of solution
Feel free to ask me any question on twitter #muhammad_khan40.
Thanks, let me know if the solution helped with your problem.
cs code:
protected void TxtNumofDays_TextChanged1(object sender, EventArgs e)
{
MTMSDTO objc = new MTMSDTO();
TxtNumofDays.Text = Session["NumofDays"].ToString();
objc.NumofDays = Convert.ToInt32(TxtNumofDays.Text);
}
protected void TxtEndDate_TextChanged(object sender, EventArgs e)
{
DateTime BeginDate = Convert.ToDateTime(TxtBeginDate.Text);
DateTime EndDate = Convert.ToDateTime(TxtEndDate.Text);
TimeSpan diff = EndDate.Subtract(BeginDate);
TxtNumofDays.Text = diff.Days.ToString();
TxtNumofDays.Focus();
}
aspx code:
<asp:TextBox ID="TxtBeginDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" style="text-align: left" Width="73px"></asp:TextBox>
<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtBeginDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton1"
PopupPosition="Right" TargetControlID="TxtBeginDate"
TodaysDateFormat="dd/MM/yyyy"> </asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtBeginDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtBeginDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkBeginDate" runat="server"
ControlToValidate="TxtBeginDate" Display="Dynamic"
ErrorMessage="You must supply a valid start date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" />
<asp:TextBox ID="TxtEndDate" runat="server" BorderColor="#0061C1"
BorderWidth="1px" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
ForeColor="#0061C1" Height="25px" ontextchanged="TxtEndDate_TextChanged"
style="text-align: left" Width="73px" AutoPostBack ="true"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server"
AlternateText="Click to show calendar" ImageUrl="Images/calendar.png" />
<asp:CalendarExtender ID="TxtEndDate_CalendarExtender" runat="server"
Enabled="True" Format="dd/MM/yyyy" PopupButtonID="ImageButton2"
PopupPosition="Right" TargetControlID="TxtEndDate"
TodaysDateFormat="dd/MM/yyyy"></asp:CalendarExtender>
<asp:RoundedCornersExtender ID="TxtEndDate_RoundedCornersExtender"
runat="server" BorderColor="Black" Enabled="True" Radius="4"
TargetControlID="TxtEndDate"></asp:RoundedCornersExtender>
<asp:CompareValidator ID="chkEndDate" runat="server"
ControlToValidate="TxtEndDate" Display="Dynamic"
ErrorMessage="You must supply a valid end date" ForeColor="Red"
Operator="DataTypeCheck" Type="Date" /><br />
<asp:CompareValidator ID="cmpBeginAndEndDates" runat="server"
ControlToCompare="TxtBeginDate" ControlToValidate="TxtEndDate"
Display="Dynamic" ErrorMessage="The end date must be after the start date"
ForeColor="Red" Operator="GreaterThan" />
i use modal popup extender to show my details in another separate window it is a panel contains some controls the problem is ::
when i click on my button which contains::
the Show() method the parent page just frozen and no popup appears at all on the other side i have a grid view when i click on the last button on it the popup appears where the other buttons on the grid view make the same behavior of my first button , i donot know what is the problem my panel visibility = true and no setting in my behind code..i view the source and i find the panel with its contents then why the popup window doesnot appear..i search alot but i donot find a solution to my problem ..
my aspx::
<asp:Panel id="master_editMode" runat="server" >
<div id="masterDiv" style="width:98%" dir="rtl">
<div id="masterControls" align="center">
<table border="0" width="98%">
<tr>
<td align="center" dir="rtl">
<asp:ObjectDataSource ID="ObjDS_AllTasks" runat="server"
SelectMethod="Get_All_Tasks" TypeName="DocumentFlowModuleDTO.TaskDTO">
</asp:ObjectDataSource>
<asp:HiddenField ID="hd_Task_Code" runat="server" />
<table>
<tr>
<td>
<asp:Label ID="Label11" runat="server" Text="Search for Task" Visible="False"></asp:Label>
</td>
<td align="right">
<asp:TextBox ID="txt_Search" runat="server" AutoPostBack="True"
ontextchanged="txt_Search_TextChanged" Width="200px" Visible="False"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="grd_AllTasks" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CssClass="Alternating" DataKeyNames="task_code"
DataSourceID="ObjDS_AllTasks"
onpageindexchanging="grd_AllTasks_PageIndexChanging"
onrowdatabound="grd_AllTasks_RowDataBound" style="margin-right: 0px">
<RowStyle VerticalAlign="Top" />
HeaderText="ÍÐÝ">
<ItemTemplate>
<asp:ImageButton ID="btn_Delete_Task" runat="server"
CommandArgument="<%# Bind('task_code') %>" Height="33px"
ImageUrl="~/Images/delete.png" oncommand="btn_Delete_Task_Command"
Width="67px" />
<cc1:ConfirmButtonExtender ID="btn_Delete_Task_ConfirmButtonExtender"
runat="server" ConfirmText="åá ÊÑíÏ ÍÐÝ æËíÞÉ ÇáÇÚÊãÇÏ ¿" Enabled="True"
TargetControlID="btn_Delete_Task">
</cc1:ConfirmButtonExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle HorizontalAlign="Right" />
</asp:GridView>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" dir="rtl">
<asp:Label ID="lbl_TaskName" runat="server" Font-Bold="True" Font-Size="13pt"></asp:Label>
</td>
</tr>
<tr>
<td align="center" dir="rtl" style="height: 196px">
<table>
<tr>
<td align="left">
<asp:Label ID="lbl_No_States" runat="server" Font-Bold="True" ForeColor="Red"></asp:Label>
</td>
<td align="right">
<asp:ImageButton ID="btn_AddStatesToTask" runat="server"
ImageUrl="Images/add.png" onclick="btn_AddStatesToTask_Click" Visible="False" />
<asp:Button ID="Dummy_btn2" runat="server" Text="Button" Style="display:none;" />
<cc1:ModalPopupExtender ID="btn_AddStatesToTask_ModalPopupExtender"
runat="server"
TargetControlID="Dummy_btn2"
BackgroundCssClass="modalBackground"
PopupControlID="pnl_Add_States"
DropShadow="True">
</cc1:ModalPopupExtender>
</td>
</tr>
</table>
<asp:HiddenField ID="hd_StateSerial" runat="server" />
<asp:HiddenField ID="hd_StateRowIndex" runat="server" />
<asp:GridView ID="grd_States" runat="server" AllowPaging="True" DataKeyNames="state_serial"
onpageindexchanging="grd_States_PageIndexChanging" Visible="False"
CssClass="Alternating" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="state_name" HeaderText="ÇáãÑÍáÉ"
ShowHeader="False" />
<asp:BoundField DataField="state_order" HeaderText="ÊÑÊíÈ ÇáãÑÍáÉ"
ShowHeader="False" />
<asp:TemplateField HeaderText="Power" ShowHeader="False">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="chb_StatePower" runat="server"
Checked='<%# Convert.ToBoolean(Eval("power_flag")) %>' Enabled="False" />
</ItemTemplate>
<ItemStyle Width="40px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="New" ShowHeader="False">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox3" runat="server" />
<asp:Button ID="Dummy_btn4" runat="server" Text="Button" Style="display:none;" />
<cc1:ModalPopupExtender ID="btn_TaskState_Edit_ModalPopupExtender" runat="server"
TargetControlID="Dummy_btn4"
BackgroundCssClass="modalBackground"
PopupControlID="pnl_Add_States"
DropShadow="True">
</cc1:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ÍÐÝ" ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="btn_TaskState_Delete" runat="server"
CommandArgument="<%# Bind('state_serial') %>" Height="26px"
ImageUrl="~/Images/delete.png" oncommand="btn_TaskState_Delete_Command"
Width="47px" />
<cc1:ConfirmButtonExtender ID="btn_TaskState_Delete_ConfirmButtonExtender"
runat="server" ConfirmText="åá ÊÑíÏ ÍÐÝ ÇáãÑÍáÉ ¿" Enabled="True"
TargetControlID="btn_TaskState_Delete">
</cc1:ConfirmButtonExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:ObjectDataSource ID="ObjectDataSource_States" runat="server"
SelectMethod="Select_TaskStates" TypeName="DocumentFlowModule.DTO.TaskStateDTO">
<SelectParameters>
<asp:Parameter Name="task_code" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
</table>
</div>
</div>
</asp:Panel>
<asp:Panel ID="pnl_Add_Task" runat="server" CssClass="modalPopup"><%-- Style="display:none;"--%>
<div id="div3" style="width: 95%">
<div id="div4" align="center">
<table>
<tr>
<td>
<asp:UpdatePanel ID="UpPnl1" runat="server">
<ContentTemplate>
<table dir="rtl" style="text-align: right">
<tr bgcolor="#f1ece2">
<th align="right" height="35" valign="middle" colspan="3">
<asp:Label ID="lbl_New_Task" runat="server" Font-Bold="False" Font-Size="14pt"
Text="ÅÖÇÝÉ æËíÞÉ ÇÚÊãÇÏ" Visible="False"></asp:Label>
<asp:Label ID="lbl_Edit_Task" runat="server" Font-Bold="False" Font-Size="14pt"
Text="ÊÚÏíá æËíÞÉ ÇÚÊãÇÏ" Visible="False"></asp:Label>
</th>
</tr>
<tr>
<td class="title" width="160">
<asp:Label ID="Label1" runat="server" Text="Task Name"></asp:Label>
</td>
<td style="width: 140px">
<asp:TextBox ID="txt_TaskName" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txt_TaskName" ErrorMessage="*" ValidationGroup="G1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="title" width="160">
<asp:Label ID="Label10" runat="server" Text="DataBase Name"></asp:Label>
</td>
<td style="width: 140px">
<asp:DropDownList ID="ddl_DataBases" runat="server" AutoPostBack="True"
ondatabound="ddl_DataBases_DataBound"
onselectedindexchanged="ddl_DataBases_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="ddl_DataBases" ErrorMessage="*" InitialValue="--Select--"
ValidationGroup="G1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="title" width="160">
<asp:Label ID="Label2" runat="server" Text="Table Name"></asp:Label>
</td>
<td style="width: 140px">
<asp:DropDownList ID="ddl_Tables" runat="server" AutoPostBack="True"
ondatabound="ddl_Tables_DataBound"
onselectedindexchanged="ddl_Tables_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="ddl_Tables" ErrorMessage="*" InitialValue="--Select--"
ValidationGroup="G1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="title" width="160">
<asp:Label ID="Label17" runat="server" Text="Table Key"></asp:Label>
</td>
<td style="width: 140px">
<asp:Label ID="lbl_Key" runat="server"></asp:Label>
<asp:CheckBoxList ID="cbl_Columns" runat="server">
</asp:CheckBoxList>
</td>
<td>
<asp:Label ID="lbl_Select_Key" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td class="title" width="160">
<asp:Label ID="Label18" runat="server" Text="Current Record State"></asp:Label>
</td>
<td style="width: 140px">
<asp:DropDownList ID="ddl_Columns" runat="server" AutoPostBack="True"
ondatabound="ddl_Columns_DataBound">
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="ddl_Columns" ErrorMessage="*" InitialValue="--Select--"
ValidationGroup="G1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="title" width="160">
<asp:Label ID="Label5" runat="server" Text="Form View "></asp:Label>
</td>
<td style="width: 140px">
<asp:TextBox ID="txt_F_View" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txt_F_View" ErrorMessage="*" InitialValue="--Select--"
ValidationGroup="G1"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="title" width="160">
<asp:Label ID="Label6" runat="server" Text="Form New"></asp:Label>
</td>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td dir="rtl" align="center">
<asp:ImageButton ID="btn_OK" runat="server" ImageUrl="~/Images/add.png"
onclick="btn_OK_Click" ValidationGroup="G1" Visible="False" />
<asp:ImageButton ID="btn_Edit" runat="server" ImageUrl="~/Images/edit.png"
onclick="btn_Edit_Click" ValidationGroup="G1" Visible="False" />
<asp:ImageButton ID="btn_Cancel_Task" runat="server" CausesValidation="False"
Height="36px" ImageUrl="~/Images/cancel.png" onclick="btn_Cancel_Task_Click" />
</td>
</tr>
</table>
</div>
</div>
</asp:Panel>
the btn_add _task does not make my popup appear just freeze the parent page
my .cs
protected void btn_Add_Task_Click(object sender, EventArgs e)
{
//AjaxControlToolkit.ModalPopupExtender modal1 = (AjaxControlToolkit.ModalPopupExtender) table1.FindControl("btn_Add_Task_ModalPopupExtender");
//modal1.Show();
grd_States.Visible = false;
lbl_No_States.Text = "";
btn_AddStatesToTask.Visible = false;
lbl_TaskName.Text = "";
//master_editMode.Visible = true;
//pnl_Add_Task.Visible = true;
btn_OK.Visible = true;
btn_Edit.Visible = false;
lbl_New_Task.Visible = true;
lbl_Edit_Task.Visible = false;
txt_TaskName.Text = "";
ddl_DataBases.ClearSelection();
ddl_Tables.Items.Clear();
ddl_Columns.Items.Clear();
cbl_Columns.Items.Clear();
txt_F_New.Text = "";
txt_F_View.Text = "";
txt_Params.Text = "";
txt_SP_Name.Text = "";
btn_Add_Task_ModalPopupExtender.Show();
}
thanks in advance
EDITED::
<table align="center" dir="rtl">
<tr>
<td >
<asp:Button ID="Dummy_btn" runat="server" Text="Button" Style="display:none;" />
<asp:Button ID="btn_Add_Task" runat="server" Text="ÅÖÇÝÉ æËíÞÉ ÇÚÊãÇÏ ÌÏíÏÉ"
onclick="btn_Add_Task_Click" Font-Bold="True" Font-Size="12pt"
ForeColor="#0066FF" />
<cc1:ModalPopupExtender ID="btn_Add_Task_ModalPopupExtender" runat="server"
TargetControlID="Dummy_btn"
PopupControlID="pnl_Add_Task"
BackgroundCssClass="modalBackground"
DropShadow="True" >
</cc1:ModalPopupExtender>
</td>
</tr>
</table>`
If you want your modal popup to be displayed when the user clicks on the btn_Add_Task button, you should set that button as the TargetControlID of the extender:
<cc1:ModalPopupExtender ID="btn_Add_Task_ModalPopupExtender" runat="server"
TargetControlID="btn_Add_Task" PopupControlID="pnl_Add_Task"
BackgroundCssClass="modalBackground" DropShadow="True" />
In your current code, the modal popup is triggered by a button named Dummy_btn, which I can't find in your markup, but which probably isn't what you want.
We had many issues with ajax popup. you might want to try the approach we have been using for past one month or so with out any issues. This approach creates a popup with out need of ajax / jquery / javascript /css/ update panel .
here:
A modal popup with out using ajax, update panel, jquery or javascript- surprisingly this seems to work