I have a modalpopup which is showed automaticaly on startup of page. I'm doing this on Page_Load event.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitiallizeAll();
}
}
private void InitiallizeAll()
{
ModalPopupExtender1.Show();
}
In aspx side I have a dropdownlist on a modalpopup but the index is always posting zero to the javascript code.
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="lnkPopup"
PopupControlID="panEdit"
BackgroundCssClass="modalBackground"
OkControlID="btnGonder"
OnOkScript="onOk()">
</asp:ModalPopupExtender>
<asp:Panel ID="panEdit" runat="server" Height="180px" Width="400px" CssClass="modalPopup">
<table width="100%">
<tr>
<td class="labelCell">
<asp:Label ID="lblBolge" Text="Bölge" runat="server" />
</td>
<td>
<asp:DropDownList ID="ddlIl" runat="server"
AutoPostBack="False"
DataTextField="Isim"
DataValueField="Id"
DataSourceID="ObjectDataSource1"
Width="176px">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetAllIl"
TypeName="ERK.Lasos.Business.CustomEntities.Il">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0"
Name="ilId"
QueryStringField="bolge"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</td>
</tr>
</table>
<br />
<asp:Button ID="btnGonder" runat="server" Text="Devam Et" />
</asp:Panel>
<a id="lnkPopup" runat="server">Show Popup</a>
And this is my javascript code
<script type="text/javascript">
function onOk() {
var e = document.getElementById("ddlIl");
var selectedIlId = e.options[e.selectedIndex].value;
window.location = "/Pages/AnaSayfa/LasosAnaSayfa.aspx?bolge=" + selectedIlId;
}
</script>
But I'm always getting selectedIlId is "0". Value is not changing whatever I select from dropdownlist
First, you should check if you got the good selected index. :
Replace temporally var selectedIlId = e.options[e.selectedIndex].value; by var selectedIlId = e.selectedIndex;
If it's OK, you should check you data source by making sure the Id field is correct, the easiest way to to this is to set DataTextField="Id" to your DropdownList and check the values that appears in it.
Related
In my single page two buttons are there. one button is using 3 tier structure to insert data in to database and it is perfectly running.
Button coding
<asp:Button ID="InsertButton1" CssClass="BUTT" runat="server" OnClick="Insert" CommandName="Insert" Text="SUBMIT" />
second button code
<asp:FormView ID="FormView1" runat="server" DefaultMode="Insert" DataKeyNames="id" DataSourceID="SqlDataSource1" EnableModelValidation="True">
<InsertItemTemplate>
<table>
<tr>
<td>
Office Address
</td>
<td>
<asp:TextBox ID="office_addressTextBox" runat="server" Text='<%# Bind("office_address") %>' />
</td>
</tr>
<tr>
<td>
Date Of Birth
</td>
<td>
<asp:TextBox ID="dobTextBox" runat="server" Text='<%# Bind("dob") %>' />
</td>
</tr>
<tr>
<td>
Sex
</td>
<td>
<asp:TextBox ID="SexTextBox" runat="server" Text='<%# Bind("Sex") %>' />
<asp:Button ID="InsertButton" runat="server" CausesValidation="true" CommandName="Insert" Text="insert" />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="Data Source=WIN-MIUHU8FBDQI\PANKIL;Initial Catalog=test;Integrated Security=True"
InsertCommand="INSERT INTO [research] ([office_address], [dob], [Sex]) VALUES
(#office_address, #dob, #Sex)" OldValuesParameterFormatString="original_{0}"
ProviderName="System.Data.SqlClient" >
<InsertParameters>
<asp:Parameter Name="office_address" Type="String" />
<asp:Parameter DbType="Date" Name="dob" />
<asp:Parameter Name="Sex" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
i want that when any one click on one button , second button also perform a insert task.
I'm unsure if there is a way to trigger that in asp. But i think JQuery can do that for you.
However a neater way to do it as stated by #Luaan is calling the click event and handle it in the cs code. This way it promotes reuse of codes and no update/change of codes problems.
asp page:
<asp:Button ID="FirstButton" CssClass="BUTT" runat="server" OnClick="onclick="button1_Click" Text="SUBMIT" />
<asp:Button ID="SecondButton" CssClass="BUTT" runat="server" OnClick="onclick="button2_Click" Text="SUBMIT" />
Here in the cs code you handle the event.
I think you want this :
private void button1_Click(object sender, EventArgs e)
{
button2_Click(sender, e);
}
However a neater way would be this:
private void button1_Click(object sender, EventArgs e)
{
InsertIntoDatabase();
}
private void button2_Click(object sender, EventArgs e)
{
InsertIntoDatabase();
}
private void InsertIntoDatabase()
{
// Your Insert into Database codes here
}
So any adjustment to your insert query can be in the method InsertIntoDatabase().
I have created an aspx page in which I want some controls to be enabled on basis of user selection.
If user selects All two radio buttons should be enabled, hide otherwise.
My declarative part is:
<tr>
<td>
<asp:Label ID="lblCommunityMembers" runat="server" Text="Community Members" />
</td>
<td>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="upCommunityMembers" runat="server">
<ContentTemplate>
<asp:RadioButton ID="rdbCommunityMembersAll" runat="server" Text="All" GroupName="grpCommMembers" Checked="true" OnCheckedChanged="rdbCommunityMembersAll_CheckedChanged" AutoPostBack="true" />
<asp:RadioButton ID="rdbCommunityMembersSelectedUsers" runat="server" Text="Selected Users" GroupName="grpCommMembers" OnCheckedChanged="rdbCommunityMembersSelectedUsers_CheckedChanged" AutoPostBack="true" />
<SharePoint:ClientPeoplePicker ID="ppCommunityMembers" runat="server" AllowMultipleEntities="true" AllowEmpty="false" Visible="false" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCommunityCatagory" runat="server" Text="Community Catagory" />
</td>
<td>
<asp:DropDownList ID="ddlCommunityCatagory" runat="server">
<asp:ListItem Value="0">---- Select One ----</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvCommunityCatagory" runat="server" InitialValue="0" ErrorMessage="Please Select Community Catagory"
ForeColor="Red" ControlToValidate="ddlCommunityCatagory" Display="Dynamic" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCommunityAccess" runat="server" Text="Required Approval?" Visible="false" />
</td>
<td>
<asp:RadioButton ID="rdbRequiredApprovalYes" runat="server" Text="Yes" GroupName="grpCommMembers" Checked="true" Visible="false" />
<asp:RadioButton ID="rdbRequiredApprovalNo" runat="server" Text="No" GroupName="grpCommMembers" Visible="false"/>
</td>
</tr>
My code behind:
protected void rdbCommunityMembersSelectedUsers_CheckedChanged(object sender, EventArgs e)
{
if (rdbCommunityMembersSelectedUsers.Checked)
{
enableControls();
}
else
{
disableControls();
}
}
protected void rdbCommunityMembersAll_CheckedChanged(object sender, EventArgs e)
{
if (rdbCommunityMembersAll.Checked)
{
disableControls();
}
else
{
enableControls();
}
}
protected void enableControls()
{
ppCommunityMembers.Visible = true;
lblCommunityAccess.Visible = true;
rdbRequiredApprovalNo.Visible = true;
rdbRequiredApprovalYes.Visible = true;
}
protected void disableControls()
{
ppCommunityMembers.Visible = false;
lblCommunityAccess.Visible = false;
rdbRequiredApprovalNo.Visible = false;
rdbRequiredApprovalYes.Visible = false;
}
If Community members are selected to all then "Required Approval?" part should get hidden.
But problem is when I select selected users then I am getting only people picker control visible, the required approval contorls are not getting displayed. What am I missing?
Your Radio Buttons rdbCommunityMembersAll and rdbCommunityMembersSelectedUsers are inside update panel, thus they are doing partial postback. To make the control visible outside the UpdatePanel you can do any one of the following:
Move rdbCommunityMembersAll and rdbCommunityMembersSelectedUsers
outside the UpdatePanel
Move the controls you need to make visible
(lblCommunityAccess, rdbRequiredApprovalNo, rdbRequiredApprovalYes)
inside UpdatePanel
Or
Instead of setting Visible="false", set style="display:none" and
trigger the visibility through javascript/jquery
Currently I have a dropdownlist with it's own sqldatasource that's populating the dropdownlist.
The ddl is inside a listviews, which also has it's on sqldatasource, insert item template.
However when we click insert the value passed to the dbase is a null.
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
</td>
<td>
<asp:TextBox ID="td_t_idTextBox" runat="server" Text='<%# Bind("td_t_id") %>' Enabled="false" />
</td>
<td>
<asp:DropDownList ID="DropDownList2iit" runat="server" DataSourceID="SqlDataSource30"
DataTextField="document_name" DataValueField="document_id"
SelectedIndex='<%# Bind("td_docid") %>'>
</asp:DropDownList>
</td>
</tr>
</InsertItemTemplate>
I have tried to use both document_id and td_docid in my sqldatasource insertparameters.
<InsertParameters>
<asp:Parameter Name="td_t_id" Type="Int32" />
<asp:Parameter Name="td_docid" Type="Int32" />
<asp:Parameter Name="document_id" Type="Int32" />
</InsertParameters>
however neither value when used will give me a actual value other than null. Is this a common occurance?
update: I ended up using the oniteminserting to do a little code behind magic
protected void ListView2_OnItemInserting(object sender, EventArgs e)
{
string sv = ((DropDownList)ListView2.InsertItem.FindControl("DropDownList2iit")).SelectedValue;
SqlDataSource31.InsertParameters.Add("document_id", sv);
}
and it works like it should.
You can try like bellow . ( i am 100% sure but hope fully it's worked)
protected void ListView2_OnItemInserting(object sender, EventArgs e)
{
string sv = ((DropDownList)e.Item.FindControl("DropDownList2iit")).SelectedValue;
SqlDataSource31.InsertParameters.Add("document_id", sv);
}
This question is very old but might help someone.
You are binding your drop down's value to selectedindex property. It should be bound to SelectedValue instead. No need of writing code for this..
Replace :
SelectedIndex='<%# Bind("td_docid") %>'>
with
SelectedValue= '<%# Bind("td_docid") %>'
could you please tell me, why custom validator (created dynamically), information here is not added to validation summary? Is it because of updatepanel? How to make it work?
I am absolutely exhausted, but cannot find appropriate solution...
MultiFreeSet control code-behind:
protected void btnPatternAdder_Click(object sender, EventArgs eventArgs)
{
var includeEventArgs = new IncludeEventArgs();
baseTSMAlertConfigEditControlWithInclude.btnPatternAdder_Click(sender, includeEventArgs);
if (includeEventArgs.Cancel)
{
/*
var ClientValidationFunctionName = string.Format("{0}_ClientValidation", ID);
Page.ClientScript.RegisterClientScriptBlock(
GetType(),
string.Format("{0}_validationScript", ID),
string.Format("function {0}(sender, eventArgs) {{ eventArgs.errormessage = '{1}', eventArgs.IsValid = false; return; }}",
ClientValidationFunctionName,
includeEventArgs.Message));
*/
var customValidator = new CustomValidator
{
//ClientValidationFunction = ClientValidationFunctionName,
ValidationGroup = ValidationGroup,
IsValid = false,
ErrorMessage = includeEventArgs.Message,
Display = ValidationDisplayType
};
Page.Validators.Add(customValidator);
}
}
MultiFreeSet control markup:
<asp:UpdatePanel ID="upFreeSet" runat="server">
<ContentTemplate>
...
<asp:PlaceHolder runat="server" ID="phIncludePattern" Visible="false">
<tr>
<td class="SubHead">[IncludeCaption]</td>
<td>
<asp:TextBox ID="txtIncludePattern" runat="server" Text="" CssClass="MediumTextBox" />
</td>
<td>
<asp:Button CommandName="ListAdder" ID="btnPatternAdder" runat="server" CssClass="buttonClass displayBlock" Text="Add" OnClick="btnPatternAdder_Click" />
</td>
</tr>
<tr>
<td class="SubHead ta">[IncludedCaption]</td>
<td>
<asp:ListBox ID="lboxIncludePattern" runat="server" SelectionMode="Multiple" Rows="7" CssClass="LargeDropDownList" />
<asp:ObjectDataSource ID="odsIncludePattern" runat="server" />
</td>
<td class="ta">
<asp:Button CommandName="ListDeleter" ID="btnPatternDeleter" runat="server" CssClass="buttonClass displayBlock" Text="Delete selected" OnClick="btnPatternDeleter_Click" />
</td>
</tr>
</asp:PlaceHolder>
...
</ContentTemplate>
Main control markup:
<asp:FormView>
<EditItemTemplate>
...
<ac:multiFreeSet ID="multiNodePatternInclusions" ValidationGroup="vgFrmConfigEdit" IgnoreCase="True" runat="server" Caption="Include node name patterns" IncludeCaption="Add node name pattern" IncludedCaption="Included node name patterns" />
<XXX:SaveButton ID="btnImgSave" runat="server" ValidationGroup="vgFrmConfigEdit" />
<XXX:CancelBackButton ID="btnImgCancel" runat="server" />
<asp:ValidationSummary ID="valSummary" runat="server" ValidationGroup="vgFrmConfigEdit" CssClass="NormalRed" ShowSummary="True" />
...
</EditItemTemplate>
</asp:FormView>
OK. Well.. I had to create a separate validation summary with separate validation group inside update panel..
I want to display a field value from a navigation property in a grid view control.
My entities are Albums and Photos and a Photo entity must be associated with an Album entity.
I want to display an albums’s name but it is never shown in the gridview control.
The following is my markup:
<h4>
<asp:DropDownList ID="ddlAlbums" runat="server" Style="padding: 3px; width: 150px;"
AutoPostBack="True">
</asp:DropDownList>
</h4>
<br />
<asp:UpdatePanel ID="pnlPhotos" runat="server" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlAlbums" />
</Triggers>
<ContentTemplate>
<asp:DataList ID="PhotosDataList" runat="server" DataKeyField="PhotoID" DataSourceID="PhotosEntityDataSource"
RepeatDirection="Horizontal" CssClass="view" RepeatColumns="5"
onitemdatabound="PhotosDataList_ItemDataBound">
<ItemTemplate>
<asp:Image ID="img" CssClass="thumbnail" ToolTip='<%#Eval("Title")%>' runat="server"
ImageUrl='<%#Eval("Caption","~/Uploads/Pictures/{0}")%>' />
<br />
**<asp:Label ID="lblAlbumName" runat="server" Text='<%#Eval("Album.Name")%>'></asp:Label>**
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Select" CommandArgument='<%#Eval("PhotoID")%>'
OnClick="lnkEdit_Click">edit</asp:LinkButton>
<asp:LinkButton ID="lnkDelete" runat="server" CommandArgument='<%#Eval("PhotoID")%>'
OnClick="DelPhoto_Click">delete</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:EntityDataSource ID="PhotosEntityDataSource" runat="server" ContextTypeName="Misagh.DAL.MisaghSchoolEntities"
EnableDelete="True" EntitySetName="Photos" Where="it.AlbumID = #AlbumID">
<WhereParameters>
<asp:ControlParameter ControlID="ddlAlbums" DefaultValue="0" DbType="Int32" PropertyName="SelectedValue"
Name="AlbumID" />
</WhereParameters>
</asp:EntityDataSource>
I would really appriciated any help
Thanks
You already handle OnItemDataBound. You can simply do:
protected void PhotosDataList_ItemDataBound(Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
// Retrieve the Label control in the current DataListItem.
Label albumName = (Label)e.Item.FindControl("lblAlbumName");
albumName.Text = (e.Item.DataItem as ICustomTypeDescriptor).GetPropertyOwner(null).Album.Name;
}
}
And set EnableFlattening="true" in your EntityDataSource declaration in your markup
Read more about a related topic here.