Friday, March 9, 2012

How to get Read only control value through SQl data Source

Hello,

I am using this sql data source control.

<asp:textboxrunat="server"id="txtFromDate" ReadOnly="true"></></asp:textbox>

<asp:textboxrunat="server"id="txtToDate" ReadOnly="true"></asp:textbox>

---------->

<asp:sqldatasourceid="dsClickInfo"runat="server"connectionstring="<%$ ConnectionStrings:activeConnectionString %>"

selectcommand="SProc_GetTransaction"selectcommandtype="StoredProcedure"><SelectParameters><asp:QueryStringParameterQueryStringField="Id"Name="MerchantID"Type="int32"/><asp:ControlParameterControlID="txtFromDate"Name="StartDate"PropertyName="Text"Type="String"DefaultValue="0"/><asp:ControlParameterControlID="txtToDate"Name="EndDate"PropertyName="Text"Type="String"DefaultValue="0"/></SelectParameters>

</asp:sqldatasource>

I abouve code txtFromDate and txtToDate are marked as readonly so sqldatasource is not able to get value from these controls.

How is it possible?

Please help me..

Hi Welcome to asp.net

I don't know the way you get value from these controls.

When I bind a textbox to field I'd like to set Enabled to false instead of the ReadOnly ,you can have a try,

<asp:TextBox ID="TextBox1" runat="server" Enabled=false Text='<%# Bind("contact_firstno") %>'></asp:TextBox>

|||

Thanks for reply..

But my problem is different..

I dont want to bind the text box. I am getting the text box value in sqldatasource control by the property

<SelectParameters>

<asp:QueryStringParameterQueryStringField="Id"Name="MerchantID"Type="int32"/>

<asp:ControlParameterControlID="txtFromDate"Name="StartDate"PropertyName="Text"

Type="String"DefaultValue="0"/>

<asp:ControlParameterControlID="txtToDate"Name="EndDate"PropertyName="Text"

Type="String"DefaultValue="0"/>

</SelectParameters>

and after that these values are passing to the DB (by the select command) for search a result according to the from date and to date.

Now if i am not making thetxtFromDate and txtToDatereadonly then getting proper result.

But if these are readonly then after click on the search button i am getting these controls values empty and dont get any changes in result according to search date.

Thanks

Rahul Panwar

|||

Sorry I misunderstood you.

Make sure Text in txtFromDate and txtToDate are only modified at ther server side (not by javascript...)

And debug your webapp to make sure the textbox value is right when you click search button .

And also make sure yourenableviewstateisnot set to false,like this:

<%@.Pagelanguage="c#"enableviewstate="false"Trace="true"%>

Hope it helps.

No comments:

Post a Comment