I'm using Visual Studio 2010 with framework 3.5 and Ajax Control Toolkit .NET 3.5.
I working on a asp.net web forms website.
On a form I have this: a textbox, an imagebutton, a button, a calendar and a requiredfieldvalidator:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p>
<br />
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:Label id="Label3" runat="server">Date</asp:Label>
<asp:textbox id="txtInitialDate" runat="server" Width="75px" MaxLength="10"></asp:textbox>
<asp:ImageButton ID="imgBegin"
ImageUrl="~/images/Icon1.jpeg" runat="server"
AlternateText="" Height="24px" Width="24px" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtInitialDate"
PopupPosition="BottomLeft" PopupButtonID="imgBegin"
>
</asp:CalendarExtender>
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtInitialDate"
Display="Dynamic"></asp:requiredfieldvalidator>
<asp:button id="Button2" runat="server" Text="Send" onclick="Button2_Click"></asp:button>
</asp:Content>
code behind:
override protected void OnInit(EventArgs e)
{
Button2.Attributes.Add("onclick", "javascript:" + Button2.ClientID + ".disabled=true;" + "javascript:" + Button2.ClientID + ".value='Processing.';" + this.GetPostBackEventReference(Button2) + ";");
base.OnInit(e);
}
protected void Button2_Click(object sender, EventArgs e)
{
string a = "some_value";
}
The interaction here is that the user clicks on the ImageButton, the calendar shows, the user clicks on a date and then hits the button.
The problem:
If I run the website and click on the ImageButton first and pick a date, then when the button is clicked no events are fired.
But if I comment the code of the validator:
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtInitialDate"
Display="Dynamic"></asp:requiredfieldvalidator>
Then the events are fired correctly.
I want to be able to use the requiredfieldvalidator, but I don't want it to create conflict with the button
Why is this happening and How can I solve this?
Thanks...
Use CausesValidation=False in the image button markup:
<asp:ImageButton ID="imgBegin" CausesValidation="False" ImageUrl="~/images/Icon1.jpeg" runat="server" Height="24px" Width="24px" />
You can add that javascript for Button2 in the markup also (instead of OnInit code-behind). Just use OnclientClick attribute in the Button2 mark up
Related
<asp:UpdatePanel ID="showsDatalistPanel" runat="server" Visible="false" UpdateMode="Always">
<ContentTemplate>
<div>
<asp:DropDownList ID="dateTimeFilter" CssClass="dateTimeFilterIdentifierCls" runat="server"
onclick="dateTimeFilter_SelectedIndexChanged" AutoPostBack="true" Visible="true" ClientIDMode="Static">
</asp:DropDownList>
<label id="dateTimeFilterLabel" runat="server" style="padding-left: 15px" visible="false">
בחירת מופע לפי תאריך
</label>
</div>
how can I call server side function on clicking the dropdown?
Thanks
If you really want to use click event then you have to simulate it using JS as DropDownList doesn't have build-in onclick functionality:
<asp:DropDownList ID="dateTimeFilter" CssClass="dateTimeFilterIdentifierCls" runat="server"
onclick="__doPostBack('dateTimeFilter', null);" AutoPostBack="true" Visible="true" ClientIDMode="Static">
</asp:DropDownList>
and then in your server code you have modify page load event accordingly:
protected void Page_Load(object sender, EventArgs e)
{
if(Page.IsPostBack)
{
if(Request.Params.Get("__EVENTTARGET").ToString() == dateTimeFilter.ClientID)
{
dateTimeFilter_SelectedIndexChanged(dateTimeFilter, null);
}
}
}
But I'm sill confused why you can't just use standard OnSelectedIndexChanged or OnSelectedValueChanged?
i wrote a code to show varified as he enters eany data. so i have 2 button to varify and then close. with label to display whether his email id is varified or not...
the code is
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="Panel1" TargetControlID="btn"
CancelControlID="btnClose" BackgroundCssClass="modalBackground" >
<asp:Label ID="Label1" runat="server" Text="Enter Your Registered Email Id"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Label" ></asp:Label>
<asp:Button ID="Button2" runat="server" CssClass="btn btn-info" OnClick="Button2_Click" Text="Varify" />
<asp:Button ID="btnClose" runat="server" Text="Close" />
code behind code is..
protected void Button2_Click(object sender, EventArgs e)
{
Label2.Visible = true;
Label2.Text = "Valid User";
Label2.ForeColor= System.Drawing.Color.Green;
//ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "showModal()", true);
// ModalPopupExtender1.Show();
}
but as i click on Button2 it closes the model..then i have to open again to see the output...I want to show the label text with out closing the ModalPopupExtender...Help me
I think postback cause this. I don't know so much about ModalPopupExtender but I can recommend you to use Jquery for button2 click and in click event make an ajax call and check whether your email is valid or not.
I used CalendarExtender with TextBox in aspnet.
<asp:TextBox ID="txtDateTime" TextMode="DateTime" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server"
TargetControlID="txtDateTime" Format="G" Animated="True" PopupPosition="Right"
FirstDayOfWeek="Monday"></ajaxToolkit:CalendarExtender>
On Page_Load event I set current date and time to TextBox's value:
txtDateTime.Text = DateTime.Now.ToString();
Then, CalendarExtender doesn't work correctly. The calendar frame become completely white. Are you help me, what is the problem here?
<asp:TextBox runat="server" ID="txtDateTime" ValidationGroup="ModalPopup"></asp:TextBox>
<asp:CalendarExtender runat="server"
TargetControlID="txtDateTime"
PopupPosition="TopRight"
Format="dd/MM/yyyy HH:mm">
</asp:CalendarExtender>
<asp:MaskedEditExtender runat="server"
ID="meeDateTime"
TargetControlID="txtDateTime"
Mask="99/99/9999 99:99"
MaskType="DateTime"
UserDateFormat= "DayMonthYear"
UserTimeFormat="TwentyFourHour"
CultureDateFormat="DMY"
CultureDatePlaceholder="/" CultureTimePlaceholder=":">
</asp:MaskedEditExtender>
On Page Load use This code
protected void Page_Load(object sender, EventArgs e)
{
txtDateTime.Text = String.Format("{0:t}", Now);
}
Link below from stackoverflow
Display Current Date Time in TextBox using MaskedEditExtender in asp.net
You need to use a MaskedExtender too.
<asp:TextBox ID="TextBoxID" runat="server"/>
<ajaxToolkit:MaskedEditExtender ID="MaskData" runat="server" TargetControlID="TextBoxID" Mask="99/99/9999" MaskType="Date"/>
Then you can use the calendarExtender
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Enabled="True" TargetControlID="TextBoxID" Format="dd/MM/yyyy"/>
I am using the ajaxtoolkit in order to make a popup where users can interact with server controls. Here is a simple implemetation:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server" />
<asp:Button ID="Button1" runat="server" Text="Button" />
<ajaxToolkit:PopupControlExtender ID="PopEx" runat="server"
TargetControlID="Button1"
PopupControlID="Panel1"
Position="Center" />
<asp:Panel ID="Panel1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="AppName" DataValueField="PK_Application"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>" SelectCommand="SELECT [AppName], [PK_Application] FROM [Application]"></asp:SqlDataSource>
</asp:Panel>
It appears to be working correctly, but when I press the button the panel flashes open then dissapears and I can't interact with it. How do I fix this?
The solution is to prevent the postback of the button click:
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onclick", "return false;");
}
I have a repeater and the items are editable through an edit button which opens a FormView in edit mode. The formView is initially invisible and the repeater visible. Once edit is pressed the repeater goes invisible then the formview becomes visible with the item to edit.
Once changes have been made the user presses update. This sets the formview invisible and the repeater visible.
The problem is the formview goes invisible but the repeater doesn't become visible. This I think is caused by the fact the formview is within an update panel and the repeater isn't? Only the items in the update panel are being altered on clicking update because it is only a partial page update.
I can't put the repeater within the update panel because there is a requirement that the public view doesn't use javascript.
Does anyone know how I could make the repeater reappear?
<asp:Repeater id="resultsRepeater" runat="server" DataSourceID="vehiclesDataSource" >
<ItemTemplate>
<asp:Label id="makeLabel" runat="server" Text='<%# Eval("Make") %>' />
<asp:Button id="editButton" runat="server" Text="Edit" CommandArgument='<%# Eval("Id") %>' OnClick="EditButton_Click" />
</ItemTemplate>
<asp:Repeater>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Panel id="insertUpdatePanel" runat="server" Visible="false">
<asp:FormView id="editformview" runat="server" DataKeyNames="Id" Datasourceid="VehiclesEditDataSource" >
<EditItemTemplate>
<uc:VehiclesEdit ID="VehiclesEdit" runat="server" />
<asp:Button id="updateButton" runat="server" OnClick="Update_Click" />
</EditItemTemplate>
</asp:FormView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
protected void EditButton_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = false;
insertUpdatePanel.Visible = true;
}
protected void Update_Click(object sender, EventArgs e)
{
resultsRepeater.Visible = true;
insertUpdatePanel.Visible = false;
}
This might help. I had a similar problem and this worked for me. I simply used ScriptManager to register the button (even iterated by row) as a postback control like this:
ScriptManager.GetCurrent(Page).RegisterPostBackControl(updateButton)
This caused a full postback and allowed me to set the visibility of a panel outside the update panel. I hope it works!
REVISED: Add a PostBackTrigger to your UpdatePanel to force a full post-back when your UpdateButton is clicked. This will hide your UpdatePanel and reveal your Repeater again. See final code below:
For more info refer to: https://stackoverflow.com/questions/2545508/how-do-i-force-full-post-back-from-a-button-within-an-updatepanel
<asp:UpdatePanel ID="updatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="updateButton" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Visible="false">
<asp:FormView ID="editformview" runat="server" DataKeyNames="Id" DataSourceID="VehiclesEditDataSource">
<EditItemTemplate>
<uc:vehiclesedit id="VehiclesEdit" runat="server" />
</EditItemTemplate>
</asp:FormView>
<asp:Button ID="updateButton" runat="server" OnClick="Update_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>