Access data in ASP without code behin - sqldatasource

I need to read some value from DB in ASP, I try this code and works fine:
<asp:SqlDataSource ID="SqlDataSource12" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:conexion1 %>"
SelectCommand="select Quantity from XW_ReqLine where ReqNbr=#reqnbr1">
<SelectParameters>
<asp:QueryStringParameter
ConvertEmptyStringToNull="True"
DefaultValue="10124"
Direction="Input"
Name="reqnbr1"
QueryStringField="string"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView15" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource12" AutoGenerateColumns="true"></asp:GridView>
I need to change DefaultValue="10124" to DefaultValue="<%# DataBinder.Eval(Container.DataItem, "ReqNbr") %>" but after that, IIS show an error. The change is because this parameter is not constant
Note: I can't access the code behind (is a comercial software) and only I can made this modifications in the ASP file.

Related

Umbraco 4.9 Display Media Picker Image in Template

I'm trying to allow content editors to be able to choose the main banner image on a page by having it chosen through a Media Picker property.
I've tried the standard inline XSLT of:
<umbraco:Item runat="server" field="banner" xslt="concat('<img src="', umbraco.library:GetMedia({0},0)/umbracoFile, '" />')" xsltDisableEscaping="true" />
But in my simple template of:
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<header class="home-header">
<div class="logo-wrapper">
<umbraco:Item runat="server" field="banner" xslt="concat('<img src="', umbraco.library:GetMedia({0},0)/umbracoFile, '" />')" xsltDisableEscaping="true" />
</div>
</header>
</asp:Content>
The rendered HTML comes out at:
<header class="home-header">
<div class="logo-wrapper">
</div>
</header>
I've read about using a macro to render images but my Umbraco knowledge is limited. If someone could provide steps for actually adding an XSLT macro, I'd be happy to try that out.
Unfortunately we are stuck on Umbraco v4.9 for now too so no <umbraco:Image /> tag for me.
I suggest you use a c# Umbraco macro instead of xslt. Umbraco 4.9 can do that.
An macro can in a differt file or simple use a inline macro:
<umbraco:Macro runat="server" language="cshtml">
#if (#Model.visual != "")
{
<img src="#Model.Media("banner", "umbracoFile")" class="foto" />
}
</umbraco:Macro>
Same as <img src="#node.Media("banner", "umbracoFile")" />
If anyone else finds this and you are not using MVC you can use this approach inside your template to get the image path you selected from the media picker
<umbraco:Item field='headerImage' runat='server'xslt='umbraco.library:GetMedia({0},true())/umbracoFile'xsltDisableEscaping='true'></umbraco:Item>
Where headerImage is the alias for your attribute name in your document type. This will render something like "/media/1002/sample.jpg" for instance

When trying to create a calendar control in asp.net in throws a namespace error?

When I am trying to create a calendar control in asp.net it throws me an error called
The 'namespace' attribute cannot contain spaces
The code written is:
<asp:TextBox ID="date1" runat="server" ></asp:TextBox>
<asp:ImageButton runat="server" ID="img1" ImageUrl="~/images/calendar.png" Height="25px" Width="25px" />
<cci:CalendarExtender runat="server" ID="cal1" PopupbuttonID="img1" TargetControlID="date1" Format="dd/mm/yyyy"></cci:CalendarExtender>
<cci:TextBoxWaterMarkExtender runat="server" TargetControlID="date1" WaterMarkText="Please Select Date To Proceed"></cci:TextBoxWaterMarkExtender>
Hoe to resolve this?

Repeater.Items only populates in Button click event when I DataBind in that event, but all textbox inputs are empty

I have a repeater that is databound to a SqlDataSource
<asp:Repeater runat="server" ID="Repeater" DataSourceID="SqlDataSource">
<ItemTemplate>
<asp:HiddenField runat="server" Value='<%# Eval("Code") %>' ID="Code" />
<asp:TextBox ID="NumberNeeded" runat="server" Text='<%# Eval("Needed") %>' /><br />
</ItemTemplate>
</asp:Repeater>
<asp:Button runat="server" ID="submit" Text="submit" OnClick="submit_Click" />
<asp:SqlDataSource ID="SqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="rtvFiltered" SelectCommandType="StoredProcedure">
<SelectParameters>
</SelectParameters>
</asp:SqlDataSource>
I want to iterate over the repeater and get the value in NumberNeeded in submit_Click
protected void submit_Click(object sender, EventArgs e)
{
this.Repeater.DataBind(); //comment this guy and this.Repeater.Items has no items
foreach (RepeaterItem item in this.Repeater.Items)
{
String code = ((HiddenField)item.FindControl("JournalCode")).Value;
// below fails because "NumberNeeded" control doesn't have the Text input by the user.
int numNeeded = Int32.Parse(((TextBox)item.FindControl("NumberNeeded")).Text);
// Doing other stuff with numNeeded
}
}
The repeater displays its items perfectly on the page, but when I click the submit button, this.Repeater.Items is empty (unless I call this.Repeater.DataBind() in that method).
I've tried explicitly data binding Repeater in Page_Load and Page_Init within and outside of a !Page.IsPostBack check, and everytime I either get no Items, or no Text value.
I have gotten an almost identical setup to work in the past, on a page without a master page. I've also noticed that this.Master.EnableViewState is false in the submit_Click method, no matter if I set it to true in Page_Init or Page_Load. this.EnableViewState is true.
As you state, you shouldn't need to call DataBind() in your code behind, so the problem may be with the data retrieval. Does your stored procedure take any parameters? Have you tried adding CancelSelectOnNullParameter="false" to your SqlDataSource?
It was the EnableViewState setting on the master page.
In the Page_Load method of the master page this.EnableViewState was getting set to false. I changed it to Page.EnableViewState and everything worked.
this.EnableViewState = Page.EnableViewState; // add to Master page Page_Load method
do'h

Silverlight app works in aspx page, not MVC Razor View

I'm having trouble getting my Silverlight app to show in an MVC3 Razor View.
When I add the application and it generates the test page (TestAppTestPage.aspx in my case), I can browse to the page and the app works fine. If I copy the same code to an MVC Razor view, then browse to the controller action, nothing happens with the application:
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/TestApp.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="5.0.61118.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=5.0.61118.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
If I look at the developer console for Chrome, the only thing I see different is the following warning: "Resource interpreted as Other but transferred with MIME type undefined". I'm not sure if this is related.
I've looked at various guides on Silverlight and MVC, and copying relevant portions of their code produces no results either. I've played with adjusting the path, using relative urls, nothing. I've also checked IIS settings, but because it works fine in the aspx test page, I suspect that's not the cause.
Based on mfanto's comment, turning my comment into an answer.
Was guessing in my comment, but I've had issues when NOT using Url.Content for any external files. So the fix would be to use something like
<param name="source" value="<%= Url.Content("~/ClientBin/TestApp.xap") %>" />
Note that that is from an MVC 2 app.

add one radio button into 2 groups

I know this is probably very elementary, but I can't seem to figure it out.
I need radio buttons that are mutually exclusive horizontally as well as vertically.
How can I assign a radio button to two groups?
Thanks in advance.
You must set GroupName property in RadioButton.
for example:
<asp:RadioButton ID="rbtnOne" runat="server" Text="One" GroupName="Number" />
<asp:RadioButton ID="rbtnTwo" runat="server" Text="Two" GroupName="Number" />
<asp:RadioButton ID="rbtnMan" runat="server" Text="Man" GroupName="Sex" />
<asp:RadioButton ID="rbtnWoman" runat="server" Text="Woman" GroupName="Sex" />
or use RadioButtonList control
<asp:RadioButtonList ID="rbtnListExample" runat="server">
<asp:ListItem Text="TestOne" />
<asp:ListItem Text="TestTwo" />
<asp:ListItem Text="TestThree" />
</asp:RadioButtonList>

Resources